public static < T > AdjustCollectionResult < T > adjustCollection ( final Collection < T > newCol , final Collection < T > toAdjust ) { final AdjustCollectionResult < T > acr = new AdjustCollectionResult <> ( ) ; acr . removed = new ArrayList <> ( ) ; acr . added = new ArrayList <> ( ) ; acr . added . addAll ( newCol ) ; if ( toAdjust != null ) { for ( final T ent : toAdjust ) { if ( newCol . contains ( ent ) ) { acr . added . remove ( ent ) ; continue ; } acr . removed . add ( ent ) ; } for ( final T ent : acr . added ) { toAdjust . add ( ent ) ; acr . numAdded ++ ; } for ( final T ent : acr . removed ) { if ( toAdjust . remove ( ent ) ) { acr . numRemoved ++ ; } } } return acr ; }
Used to adjust a collection toAdjust so that it looks like the collection newCol . The collection newCol will be unchanged but the result object will contain a list of added and removed values .