i'm still stuck on this
i think, as blindfish says , i am "setting a reference to the original array rather than creating a true copy".
my code:
ObjectA [] objecta= new ObjectA[objecta];
void setup() {
//data is loaded from an xml file
objecta[i] = new ObjectA(id, color(H, S, B), area, new PVector(position.x, position.y)); //defines ObjectA
//add associates to arrayList of ObjectA and ObjectB
objecta[i].associates.add(asso1);
objecta[i].objectb.associates.add(asso1);
objecta[i].associates.add(asso2);
objecta[i].objectb.associates.add(asso2);
}
////////////////////////////////////////////////////////////////////
class ObjectA{
ObjectB objectb;
ArrayList objectCs;
PVector origin;
ArrayList associates = new ArrayList();
int objectcCount = population;
ObjectA(int id, int colour, int Size, PVector loc) {
objectb= new ObjectB (id, colour, Size, loc);
//ObjectC
objectCs = new ArrayList();
origin = loc.get();
for (int i = 0; i < population; i++) {
objectCs.add(new objectC(id, Size, origin, false, i, associates));
//i think this is were i go wrong passing the associates to objectCs }
}
////////////////////////////////////////////////////////////////////
class ObjectB {
int id;
color colour;
int Size;
int x;
int y;
PVector position;
ArrayList associates = new ArrayList();
ObjectB(int identity, int c, int area, PVector loc) {
id = identity;
colour = c;
Size = area;
position = loc.get();
}
////////////////////////////////////////////////////////////////////
class objectC{
ArrayList associates = new ArrayList();
objectC(int identity, int Size, PVector loc, boolean mode, int whom, ArrayList asso) {
associates = asso;
}
ObjectA is composed of ObjectB and ObjectC. ObjectCs is an arrayList.
how can i copy the arrayList associates of either ObjectA or ObjectB to each ObjectC?
Thanks