aboutsummaryrefslogtreecommitdiffstats
path: root/abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java
diff options
context:
space:
mode:
Diffstat (limited to 'abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java')
-rw-r--r--abi-check-plugin/src/main/java/com/yahoo/abicheck/setmatcher/SetMatcher.java31
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;
+ }
+}