Source:
private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry<Parameter, List<Mapping>> entryByParam, List<Mapping> singleTargetReferences) { List<Mapping> mappings = entryByParam.getValue(); List<Mapping> nonNested = new ArrayList<Mapping>(); List<Mapping> appliesToAll = new ArrayList<Mapping>(); List<Mapping> sourceParameterMappings = new ArrayList<Mapping>(); Map<PropertyEntry, List<Mapping>> mappingsKeyedByProperty = new LinkedHashMap<PropertyEntry, List<Mapping>>(); for ( Mapping mapping : mappings ) { Mapping newMapping = mapping.popSourceReference(); if ( newMapping != null ) { PropertyEntry property = first( mapping.getSourceReference().getPropertyEntries() ); if ( !mappingsKeyedByProperty.containsKey( property ) ) { mappingsKeyedByProperty.put( property, new ArrayList<Mapping>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } else if ( mapping.getSourceReference() == null ) { appliesToAll.add( mapping ); } else { nonNested.add( mapping ); } } boolean hasNoMappings = mappings.isEmpty(); Parameter sourceParameter = entryByParam.getKey(); List<Mapping> singleTargetReferencesToUse = extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( singleTargetReferences, sourceParameterMappings, hasNoMappings, sourceParameter ); populateWithSingleTargetReferences( mappingsKeyedByProperty, singleTargetReferencesToUse, PROPERTY_EXTRACTOR ); for ( Map.Entry<PropertyEntry, List<Mapping>> entry : mappingsKeyedByProperty.entrySet() ) { entry.getValue().addAll( appliesToAll ); } List<Mapping> notProcessedAppliesToAll = new ArrayList<Mapping>(); if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { nonNested.addAll( appliesToAll ); } else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { notProcessedAppliesToAll.addAll( appliesToAll ); } return new GroupedSourceReferences( mappingsKeyedByProperty, nonNested, notProcessedAppliesToAll, sourceParameterMappings ); }

Target:
private GroupedSourceReferences groupByPoppedSourceReferences(Map.Entry<Parameter, List<Mapping>> entryByParam, List<Mapping> singleTargetReferences) { List<Mapping> mappings = entryByParam.getValue(); List<Mapping> nonNested = new ArrayList<Mapping>(); List<Mapping> appliesToAll = new ArrayList<Mapping>(); List<Mapping> sourceParameterMappings = new ArrayList<Mapping>(); Map<PropertyEntry, List<Mapping>> mappingsKeyedByProperty = new LinkedHashMap<PropertyEntry, List<Mapping>>(); for ( Mapping mapping : mappings ) { Mapping newMapping = mapping.popSourceReference(); if ( newMapping != null ) { PropertyEntry property = first( mapping.getSourceReference().getPropertyEntries() ); if ( !mappingsKeyedByProperty.containsKey( property ) ) { mappingsKeyedByProperty.put( property, new ArrayList<Mapping>() ); } mappingsKeyedByProperty.get( property ).add( newMapping ); } else if ( mapping.getSourceReference() == null ) { appliesToAll.add( mapping ); } else { nonNested.add( mapping ); } } boolean hasNoMappings = mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty(); Parameter sourceParameter = entryByParam.getKey(); List<Mapping> singleTargetReferencesToUse = extractSingleTargetReferencesToUseAndPopulateSourceParameterMappings( singleTargetReferences, sourceParameterMappings, hasNoMappings, sourceParameter ); populateWithSingleTargetReferences( mappingsKeyedByProperty, singleTargetReferencesToUse, PROPERTY_EXTRACTOR ); for ( Map.Entry<PropertyEntry, List<Mapping>> entry : mappingsKeyedByProperty.entrySet() ) { entry.getValue().addAll( appliesToAll ); } List<Mapping> notProcessedAppliesToAll = new ArrayList<Mapping>(); if ( mappingsKeyedByProperty.isEmpty() && !nonNested.isEmpty() ) { nonNested.addAll( appliesToAll ); } else if ( mappingsKeyedByProperty.isEmpty() && nonNested.isEmpty() ) { notProcessedAppliesToAll.addAll( appliesToAll ); } return new GroupedSourceReferences( mappingsKeyedByProperty, nonNested, notProcessedAppliesToAll, sourceParameterMappings ); }