In my day-to-day work, I encounter several interesting programming patterns that I don’t have a name for. Maybe you have?! So name the following pattern:
if ( !trans.getWeights ().isEmpty () ) {
final Collection<Weight> weightList = trans.getWeights ();
WeightVo weightVo = null;
for (final Weight weight : weightList) {
weightVo = getWeightDao ().toWeightVo ( weight );
break;
}
truckVo.setWeightVo ( weightVo );
}
While one can argue if this one-liner is more readable and understandable:
truckVo.setWeightVo ( trans.getWeights().isEmpty() ? null : getWeightDao ().toWeightVo ( trans.getWeights().get(0) ));
The following definitely is:
if ( !trans.getWeights ().isEmpty () ) {
truckVo.setWeightVo ( getWeightDao ().toWeightVo ( trans.getWeights().get(0) ) );
}