java - Linked list looping and addfirst -
why not working? looping on trxfifoarray list , passing object items result list. need split amounts in 2 need addfirst 2 amount result list. amounts in arraylist [-9.0000, -6.0000]. loop amount list addfirst on result , items added same amount list has 2 different amount.
linkedlist<invtqatracer> trxfifoarray = new linkedlist<invtqatracer>(); linkedlist<invtqatracer> result = new linkedlist<invtqatracer>(); invtqatracer trx = new invtqatracer(); int trxdocoref = 0; (int j = list.size() - 1; j >= 0; j--) { trx = list.get(j); system.out.printf("%12.4f %4s%10d %12s%n", trx.gettrxqty(), trx.getdoctype(), trx.getordno(), trx.getlocno()); list<bigdecimal> auxamounts = new arraylist<bigdecimal>(); if (trx.getdoctype().compareto("ov") == 0 || trx.getdoctype().compareto("xv") == 0) { //do ... } else { bigdecimal auxamount = bigdecimal.zero; boolean needremove = false; (invtqatracer tfifo : trxfifoarray) { if (trx.getdoctype().compareto("it") == 0) { auxamounts.add(tfifo.gettrxqty().negate()); } } if (needremove) { iterator<invtqatracer> iterator = trxfifoarray.iterator(); int count = 0; while (iterator.hasnext()) { invtqatracer iqt = iterator.next(); if (iqt.gettrxqty().compareto(bigdecimal.zero) == 0) { count++; iterator.remove(); } } } } if (!auxamounts.isempty()) { (bigdecimal asss : auxamounts) { system.out.println(asss); trx.settrxqty(asss); result.addfirst(trx); } } else { result.addfirst(trx); } (invtqatracer invtqt : trxfifoarray) { system.out.printf("%20s%2s%12.4f %10d %12s%10d%n", " ----------------> ", invtqt.getdoctype(), invtqt.gettrxqty(), invtqt.getordno(), invtqt.getlocno(), invtqt.getdocno()); } }
this code add 2 records -6.000000 value printing out both of them. hope understand code. please help!!!
thanks.
thanks help!
am finding problem in code. code needs updated this
if (!auxamounts.isempty()) { linkedlist<invtqatracer> result = new linkedlist<invtqatracer>(); //updated here invtqatracer trx = null; list<bigdecimal> auxamounts = new arraylist<bigdecimal>(); //[-9.000000, -6.000000] (bigdecimal asss : auxamounts) { system.out.println(asss); //updated here trx = new invtqatracer(); trx.settrxqty(asss); result.addfirst(trx); } } else { result.addfirst(trx); }
one more change identified inside else loop needremove value set false default , below checking whether true in if loop. think 1 can removed.
Comments
Post a Comment