Skip to content

Instantly share code, notes, and snippets.

@Walletau
Created April 1, 2017 16:59
Show Gist options
  • Save Walletau/13d74a4589d722f952dda5985239031a to your computer and use it in GitHub Desktop.
Save Walletau/13d74a4589d722f952dda5985239031a to your computer and use it in GitHub Desktop.
RH Snip2
//Method consumes two sets of Ids and returns a map of sets
//Primarily used for comparison of existing and new memberships to see what existing records have to be removed
public static Map<String, Set<Id>> compareSets(Set<Id> setOne, Set<Id> setTwo) {
Map<String, Set<Id>> comparisonMap = new Map<String, Set<Id>>{
'In_First_Set' => new Set<Id>(),
'Present_In_Both' => new Set<Id>(),
'In_Second_Set' => new Set<Id>()
};
for (String setOneString : setOne) {
if (setTwo.contains(setOneString))
comparisonMap.get('Present_In_Both').add(setOneString);
else
comparisonMap.get('In_First_Set').add(setOneString);
}
for (String setTwoString : setTwo) {
if (!setOne.contains(setTwoString))
comparisonMap.get('In_Second_Set').add(setTwoString);
}
return comparisonMap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment