Created
August 10, 2011 18:22
-
-
Save djKianoosh/1137690 to your computer and use it in GitHub Desktop.
compare lists of multiline strings in groovy
This file contains 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
def first = """item1 | |
item2 | |
item3""" | |
def second = """item2 | |
item3 | |
item4 | |
item5 | |
item6""" | |
List list1 = makeList(first) | |
List list2 = makeList(second) | |
def makeList(list) { | |
List created = new ArrayList() | |
list.eachLine { line -> | |
created.add(line) | |
} | |
return created | |
} | |
def unique1 = list1 as Set | |
def unique2 = list2 as Set | |
assert unique1.size() == list1.size() | |
assert unique2.size() == list2.size() | |
def common = list1.intersect(list2) | |
print "Common: " | |
println common | |
def diff = list1.plus(list2) | |
diff.removeAll(common) | |
print "Diff: " | |
println diff | |
def remove = diff.intersect(list1) | |
print "Remove: " | |
println remove | |
def add = diff.intersect(list2) | |
print "Add: " | |
add.each { line -> | |
println line | |
} | |
println "Remove " + remove.size() + " and add " + add.size() + " items" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment