mardi 10 mars 2015

Java ArrayList of ArrayList of integers not working right



I am working on a project that works with a large number of integers, i decided to use an ArrayList< ArrayList< Integers>> called ALL_PIXELS. i am having trouble getting my values in my arrayList or Arraylists to be unique. When i check the code with some basic test in the for loop everything is ok, once out of the for loop all the values of the sub array are the same, which they should not be. here is some code i have, maybe someone can help me. I have done a lot of testing with system.Out statements and have commented them out. i have found the problem to be that my ArrayList ALL_PIXELS seems to ok inside the for loop but after the for loop all subarrays in it are the same which is a problem.


//why is this not making ALL_PIXELS unique for each row .............



for (int i = 0; i < FRAME_HEIGHT; i++) {

HashMap<String, Double> t = boundsHistory.get(zoomNum);
PI task = new PI(i, t);
//this is the problem. some where
ArrayList<Integer> temp = new ArrayList<Integer>();
temp = task.execute();
//System.out.println(temp);
ALL_PIXELS.add(temp);
//System.out.println(ALL_PIXELS.get(i)); //still unique here....WHYYYYYYY
//System.out.println(temp); //this shows that temp is a unique array each row

}// end for loop



//why is all pixels seting the same vales to all of its sub arrays
//System.out.println(ALL_PIXELS.get(3));
//System.out.println(ALL_PIXELS.get(300));


some additional code from the class that gets called


public ArrayList execute() {



rowList = computePi(row);
//System.out.println(rowList);
return rowList;
}


and that last method


public static ArrayList computePi(int row) {



for(int column = 0; column<frame_width; column++){
double x0 = getScaledX(column);
double y0 = getScaledY(row);
double x = 0.0;
double y = 0.0;
int iteration = 0;

while((x*x + y*y < 2*2) && iteration <max_iteration){
double xtemp = x*x - y*y + x0;
y = 2*x*y + y0;
x = xtemp;
iteration++;
}
//System.out.println("row number "+row + ": column number " + column+ ": " + " iterations "+iteration);
if(iteration < max_iteration){

//image.setRGB(column,row,colors[iteration-1]);
rowList.add(iteration-1);
} else{
//image.setRGB(column,row,0);
rowList.add(0);
}
}
return rowList;

}//end compute pi



Aucun commentaire:

Enregistrer un commentaire