my arraylistS in a covering arraylist behave like the same instance.
i manupulate one of them with
i=0; manupulate((ArrayList)theCoveringRootArrayList.get(i));
, and all the sub arraylists have become effected of the manupulation.
i did my homework i googled a little but in google it was said: "create new instance with myvar=new myobject()"
i have already done so.
here is the code:
ArrayList denemeKombinasyonuCumleKelimesiListesiListesi=new ArrayList();
int i=0,j=0;
ArrayList<CumleKelimesi> geciciListe=new ArrayList<CumleKelimesi>();
while(matris[0][j]!=-1){
geciciListe=new ArrayList<CumleKelimesi>();
i=0;
while(i<cumle.cumleKelimeleri.size()){
if(!cumle.cumleKelimeleri.get(i).noktalamaMi){
geciciListe.add(cumle.cumleKelimeleri.get(i).olasilikliKelimeler.get(matris[i][j]));
}else{
geciciListe.add(cumle.cumleKelimeleri.get(i));
}
i++;
}
denemeKombinasyonuCumleKelimesiListesiListesi.add(geciciListe);
j++;
}
i=0;
int enAzAyristirilamayan=9999;
int enAzAyristirilamayanliListeninYeri=0;
while(i<denemeKombinasyonuCumleKelimesiListesiListesi.size()){
ArrayList<CumleKelimesi> cka=new ArrayList<CumleKelimesi>();
cka.addAll((ArrayList)denemeKombinasyonuCumleKelimesiListesiListesi.get(i));
int ayristirilamayanSayisi=Ayristirici.ayristirmaAlgoritmasi(cka);
if(ayristirilamayanSayisi<enAzAyristirilamayan){
enAzAyristirilamayan=ayristirilamayanSayisi;
enAzAyristirilamayanliListeninYeri=i;
}
denemeKombinasyonuCumleKelimesiListesiListesi.set(i, cka);
i++;
}
geciciListe=(ArrayList)denemeKombinasyonuCumleKelimesiListesiListesi.get(enAzAyristirilamayanliListeninYeri);
return geciciListe;
as you can see i do everything to make feel them they are different instances but, every one is effected with manupulate method. my variables name are in turkish but i think you can see what is what
for example
geciciliste=a temp list
denemeKombinasyonuCumleKelimesiListesiListesi=the encapsulating list as arraylist of arraylists what can be the problem thanks in advance
----------------edit---------------------------------------------------------------------
here is my tryings for deep copy task:
ArrayList<ArrayList<CumleKelimesi>> denemeKombinasyonuCumleKelimesiListesiListesi=new ArrayList<ArrayList<CumleKelimesi>>();
int i=0,j=0;
ArrayList<CumleKelimesi> geciciListe=new ArrayList<CumleKelimesi>();
while(matris[0][j]!=-1){
geciciListe=new ArrayList<CumleKelimesi>();
i=0;
while(i<cumle.cumleKelimeleri.size()){
if(!cumle.cumleKelimeleri.get(i).noktalamaMi){
geciciListe.add(cumle.cumleKelimeleri.get(i).olasilikliKelimeler.get(matris[i][j]));
}else{
geciciListe.add(cumle.cumleKelimeleri.get(i));
}
i++;
}
denemeKombinasyonuCumleKelimesiListesiListesi.add(geciciListe);
j++;
}
i=0;
int enAzAyristirilamayan=9999;
int enAzAyristirilamayanliListeninYeri=0;
while(i<denemeKombinasyonuCumleKelimesiListesiListesi.size()){
ArrayList<CumleKelimesi> cka=new ArrayList<CumleKelimesi>();
MetindenGrafOlusturma.copy(denemeKombinasyonuCumleKelimesiListesiListesi.get(i),cka);
int ayristirilamayanSayisi=Ayristirici.ayristirmaAlgoritmasi(cka);
if(ayristirilamayanSayisi<enAzAyristirilamayan){
enAzAyristirilamayan=ayristirilamayanSayisi;
enAzAyristirilamayanliListeninYeri=i;
}
denemeKombinasyonuCumleKelimesiListesiListesi.set(i, cka);
i++;
}
geciciListe=(ArrayList)denemeKombinasyonuCumleKelimesiListesiListesi.get(enAzAyristirilamayanliListeninYeri);
return geciciListe;
}
public static void copy(ArrayList theList,ArrayList deepCopy) { //deepCopy = new ArrayList();//if i un comment deepcopy would be empty for (CumleKelimesi ck : theList) deepCopy.add(ck.clone()); }
here is the CumleKelimesi object s clone method
public CumleKelimesi clone()
{
try
{
return (CumleKelimesi)super.clone();
}
catch( CloneNotSupportedException e )
{
return null;
}
}
if all these are wrong please advise a different deep copy method and i am very confused