question: public static Map < Unit , Unit > mapTransportsToLoadUsingMinTransports ( final Collection < Unit > units , final Collection < Unit > transports ) { final List < Unit > canBeTransported = sortByTransportCostDescending ( units ) ; final List < Unit > canTransport = sortByTransportCapacityDescendingThenMovesDescending ( transports ) ; final Map < Unit , Unit > mapping = new HashMap < > ( ) ; Optional < Unit > finalTransport = Optional . empty ( ) ; for ( final Unit currentTransport : canTransport ) { final int capacity = TransportTracker . getAvailableCapacity ( currentTransport ) ; final int remainingCost = getTransportCost ( canBeTransported ) ; if ( remainingCost <= capacity ) { if ( ! finalTransport . isPresent ( ) || capacity < TransportTracker . getAvailableCapacity ( finalTransport . get ( ) ) ) { finalTransport = Optional . of ( currentTransport ) ; } continue ; } if ( finalTransport . isPresent ( ) ) { break ; } loadMaxUnits ( currentTransport , canBeTransported , mapping ) ; } if ( finalTransport . isPresent ( ) ) { loadMaxUnits ( finalTransport . get ( ) , canBeTransported , mapping ) ; } return mapping ; }
target:  Returns a map of unit -> transport. Tries load max units into each transport before moving to next.