diff options
author | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-30 12:26:42 +0100 |
---|---|---|
committer | Ilpo Ruotsalainen <ilpo.ruotsalainen@oath.com> | 2018-11-30 12:26:42 +0100 |
commit | 233f44b0585d02d1f4fd100eead9d274f4bdb9ef (patch) | |
tree | b3415becc024bed6bceb33282bf5c35db29d7012 /abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher | |
parent | 4ab17a2abf972fe0892469f3e0205acc21e24975 (diff) |
Generalize set comparison method.
Diffstat (limited to 'abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher')
-rw-r--r-- | abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java b/abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java new file mode 100644 index 00000000000..56b08bef74f --- /dev/null +++ b/abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java @@ -0,0 +1,31 @@ +package com.yahoo.abicheck.setmatcher; + +import com.google.common.collect.Sets; +import java.util.Set; +import java.util.function.Consumer; +import java.util.function.Predicate; + +public class SetMatcher { + + public static <T> boolean compare(Set<T> expected, Set<T> actual, Predicate<T> itemsMatch, + Consumer<T> onMissing, Consumer<T> onExtra) { + boolean mismatch = false; + Set<T> missing = Sets.difference(expected, actual); + for (T item : missing) { + mismatch = true; + onMissing.accept(item); + } + Set<T> extra = Sets.difference(actual, expected); + for (T item : extra) { + mismatch = true; + onExtra.accept(item); + } + Set<T> both = Sets.intersection(actual, expected); + for (T item : both) { + if (!itemsMatch.test(item)) { + mismatch = true; + } + } + return !mismatch; + } +} |