I have a for loop, where i check if there is a certain key in a HashMap, if the key is not there, it should put a new association in the HashMap. The problem is that that it puts the association, but by the next iteration of the loop the association is gone! I don't get it!
public void DrawBoard(ArrayList<Integer[]> BoardList, int FrameX, int FrameY){
StdDraw.setCanvasSize(FrameX*50, FrameY*50);
StdDraw.clear(new Color(0,0,0));
StdDraw.setXscale(0, FrameX);
StdDraw.setYscale(FrameY, 0);
Map<Integer[], Color> Coloring = new HashMap<Integer[], Color>();
for(int i = 0; i < BoardList.size(); i++){
Integer[] Rectangle = BoardList.get(i);
Random rand = new Random();
Integer[] ColorCheck = {Rectangle[2], Rectangle[3]};
if(Coloring.containsKey(ColorCheck)){
StdDraw.setPenColor(Coloring.get(ColorCheck));}
else{
Color newColor = new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
Coloring.put(ColorCheck, newColor);
StdDraw.setPenColor(newColor);
}
double x1 = Rectangle[0];
double y1 = Rectangle[1];
double x2 = Rectangle[2];
double y2 = Rectangle[3];
StdDraw.filledRectangle(x1+(x2/2), y1+(y2/2), x2/2, y2/2);
}
}