Question

Given the below code, is there some reason that when the final if-else statement steps into the else clause, if I un-comment the two lines of code and comment the "FOOZANAZABAR" and "TESTCAIRO" lines, that it would not add those lines into the LinkedHashSet? It appears to add values.add(new BigDecimal(PEUNIT).multiply(new BigDecimal(1000)).toString()); correctly when the logic drops into the else clause, but will not add the BD.ZERO or the PEFAMT to that field DESPITE the fact they are strings.

As a note, the ZERO and PEFAMT are BigDecimal's that are converted to a string. These are the only two values that are giving me grief. Any direction would be greatly 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"));
            ZERO = 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 the ResultSet.  ", sqlEx);
    }
    return returnableMap;
}

Thank you in advance.

  • Josh
Was it helpful?

Solution

Please note that the underlying data structure you're using here is a SET which means it won't let you add duplicates. In all probability, the string values of BD.ZERO and PEFAMT must already be present in your values set and are hence getting ignored.

If this turns out to be the case simply switch to using LinkedList<String> that allows you to have duplicates.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top