blob: 56b08bef74f636b12ec426647f71db5d798fdc77 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}
}
|