void (Collection<String> explicitProfiles, Collection<String> temporarilyRemovedExplicitProfiles, Collection<String> available) { Collection<String> removedProfiles = new HashSet<>(explicitProfiles); removedProfiles.removeAll(available); temporarilyRemovedExplicitProfiles.addAll(removedProfiles); Collection<String> restoredProfiles = new HashSet<>(temporarilyRemovedExplicitProfiles); restoredProfiles.retainAll(available); temporarilyRemovedExplicitProfiles.removeAll(restoredProfiles); explicitProfiles.removeAll(removedProfiles); explicitProfiles.addAll(restoredProfiles); }