WTF code fragments
Those code fragments are real-life production fragments used in large corporate systems.
Why should I just return only the value I need?
// Do database query to request all statements matching the filter
accountStatements = listStatements.execute( filter, null, balance.getCurrencyDate(), null, sortFilter, sortOrdering );
AccountStatement lastStatement = null;
if( accountStatements.size() > 0 ) {
logger.debug("found " + accountStatements.size() + " statements for this currencyBalance... take last..." );
lastStatement = (AccountStatement)accountStatements.get( accountStatements.size()-1 );
accountStatements.clear();
} else {
logger.debug( "Nothing found for code " + balance.getGlobesCode().getValue() + "..." );
}
Lets take the last value of a list by walking over all entries
for (int i = 0; i < result.size(); i++) {
final CurrencyBalance currencyBalance = (CurrencyBalance) result.get(i);
if (currencyBalance.getClosingBalance() == null) {
curValue = null;
} else {
curValue = currencyBalance.getClosingBalance().getAmount().getValue();
}
}