Name that pattern

In my day to day work I encounter several interesting programming pattern that I don’t have a name for. Maybe you have?! So name the following pattern:

[sourcecode language=”java”]
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 );
}
[/sourcecode]

While one can argue if this one-liner is more readable and understandable:

[sourcecode language=”java”]
truckVo.setWeightVo ( trans.getWeights().isEmpty() ? null : getWeightDao ().toWeightVo ( trans.getWeights().get ( 0 ) ) );
[/sourcecode]

The following definitely is:

[sourcecode language=”java”]
if ( !trans.getWeights ().isEmpty () )
{
truckVo.setWeightVo ( getWeightDao ().toWeightVo ( trans.getWeights().get ( 0 ) ) );
}
[/sourcecode]

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.