java - Strange issue with populating LinkedHashSet -
given below code, there reason when final if-else statement steps else clause, if un-comment 2 lines of code , comment "foozanazabar" , "testcairo" lines, not add lines linkedhashset? appears add values.add(new bigdecimal(peunit).multiply(new bigdecimal(1000)).tostring()); correctly when logic drops else clause, not add bd.zero or pefamt field despite fact strings.
as note, 0 , pefamt bigdecimal's converted string. these 2 values giving me grief. direction appreciated.
public static linkedhashmap<string, linkedhashset<string>> converttransactiontabledata(resultset rs) { linkedhashmap<string, linkedhashset<string>> returnablemap = new linkedhashmap<string, linkedhashset<string>> (); try { while (rs.next()){ string pefamt, pepoln, mcisst, pebrcd, peeffy, peplan; string peunit, petrnc, peco, peityp, zero; pepoln = rs.getstring("pepoln"); mcisst = rs.getstring("mcisst"); pebrcd = rs.getbigdecimal("pebrcd").tostring(); peeffy = rs.getbigdecimal("peeffy").tostring(); peplan = rs.getstring("peplan"); peunit = rs.getbigdecimal("peunit").tostring(); pefamt = rs.getbigdecimal("pefamt").tostring(); petrnc = rs.getstring("petrnc"); peco = rs.getstring("peco"); peityp = dataconverter.resetinsurancetype(rs.getstring("peityp")); 0 = bigdecimal.zero.toplainstring(); string policynumber = pepoln; linkedhashset<string> values = new linkedhashset<string>(); values.add(mcisst); values.add(pebrcd); values.add(peeffy); values.add(peplan); values.add(peunit); if (peplan.equalsignorecase("hsre")) { values.add(new bigdecimal(peunit).multiply(new bigdecimal(1000)).tostring()); } else { values.add(pefamt); } values.add(petrnc); values.add(peco); values.add(peityp); if (dataconverter.teststringtoint(petrnc)) { if (integer.valueof(petrnc) >= 20 && integer.valueof(petrnc) <= 29) { values.add(pefamt); values.add(zero); values.add(zero); } else { values.add("foozanzabar"); values.add("testcairo"); // values.add(zero); // values.add(pefamt); values.add(new bigdecimal(peunit).multiply(new bigdecimal(1000)).tostring()); } } returnablemap.put(policynumber, values); } } catch (sqlexception sqlex) { logger.error("problem converting resultset. ", sqlex); } return returnablemap; }
thank in advance.
- josh
please note underlying data structure you're using here set means won't let add duplicates. in probability, string values of bd.zero , pefamt must present in values
set , hence getting ignored.
if turns out case switch using linkedlist<string>
allows have duplicates.