private String safeApply ( Collection < InstanceContextBean > instances , Options options , String componentPath ) throws IOException { // Parse the filter. String installerName = ( String ) options . hash . get ( "installer" ) ; final InstanceFilter filter = InstanceFilter . createFilter ( componentPath , installerName ) ; // Apply the filter. final Collection < InstanceContextBean > selectedInstances = filter . apply ( instances ) ; // Apply the content template of the helper to each selected instance. final StringBuilder buffer = new StringBuilder ( ) ; final Context parent = options . context ; int index = 0 ; final int last = selectedInstances . size ( ) - 1 ; for ( final InstanceContextBean instance : selectedInstances ) { final Context current = Context . newBuilder ( parent , instance ) . combine ( "@index" , index ) . combine ( "@first" , index == 0 ? "first" : "" ) . combine ( "@last" , index == last ? "last" : "" ) . combine ( "@odd" , index % 2 == 0 ? "" : "odd" ) . combine ( "@even" , index % 2 == 0 ? "even" : "" ) . build ( ) ; index ++ ; buffer . append ( options . fn ( current ) ) ; } return buffer . toString ( ) ; }
Same as above but with type - safe arguments .