Created
August 5, 2010 20:55
-
-
Save ejhayes/510362 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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