Skip to content

Instantly share code, notes, and snippets.

@ejhayes
Created August 5, 2010 20:55
Show Gist options
  • Save ejhayes/510362 to your computer and use it in GitHub Desktop.
Save ejhayes/510362 to your computer and use it in GitHub Desktop.
<cfscript>
// our pretend version of the pests that we input by a user
pests = [5,6,10];
rev = EntityLoadByPK("Revisions",1);
// get the id of all matching pests
ormPests = JavaCast("string[]",ormExecuteQuery("select Pest.Code from RevisionPests where Revision.Id=?",[rev.getId()]));
dbPests = ArrayNew(1);
for( i=1; i<=ArrayLen(ormPests); i++){
ArrayAppend(dbPests,javaCast("string",ormPests[i]));
}
// find matching
matching = createObject("java", "java.util.HashSet").init(dbPests);
matching.retainAll(pests);
// what needs to be removed?
toRemove = createObject("java", "java.util.HashSet").init(dbPests);
toRemove.removeAll(matching);
// what needs to be added?
toAdd = createObject("java", "java.util.HashSet").init(pests);
toAdd.removeAll(matching);
WriteDump(toRemove.toArray());
WriteDump(toAdd.toArray());
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment