I have two loops which I am using to create a file, if the clientID in the client loop is the same as the id in the valuation loop then create a row. Then if the month value is the same as the previous month value we need to add up the values.
This all works fine but i was wondering if anyone can think of a better way?
for (Clients cl : clientList) {
//in loop so use stringbuilder
StringBuilder sb = new StringBuilder();
sb.append(cl.getId());
sb.append(",");
sb.append(cl.getFirstName());
sb.append(" ");
sb.append(cl.getLastName());
sb.append(",");
row = sb.toString();
for (Valuations vl : valList) {
year = vl.getYear();
//if we are on a new month
if (!month.equals(vl.getMonth()) && !month.equals("")) {
//add row and reset values
if(!vl.isNanError()){
data.add(row + month + "," + year + ",£" + cash);
}
cash = 0;
month = "";
done = false;
}
if (cl.getId().equals(vl.getClientId())) {
if (!done) {
row = sb.toString();
cash = 0;
month = vl.getMonth();
done = true;
}
}
cash += vl.getValue();
}
}
//add the last row after the loop breaks.
data.add(row + month + "," + year + ",£" + cash);