@Override public EquatableValueSet complement() { return new EquatableValueSet(type, !whiteList, entries); }
static EquatableValueSet none(Type type) { return new EquatableValueSet(type, true, Collections.emptySet()); }
static EquatableValueSet all(Type type) { return new EquatableValueSet(type, false, Collections.emptySet()); }
static EquatableValueSet copyOf(Type type, Collection<Object> values) { return new EquatableValueSet(type, true, values.stream() .map(value -> ValueEntry.create(type, value)) .collect(toSet())); }
static EquatableValueSet of(Type type, Object first, Object... rest) { HashSet<ValueEntry> set = new HashSet<>(rest.length + 1); set.add(ValueEntry.create(type, first)); for (Object value : rest) { set.add(ValueEntry.create(type, value)); } return new EquatableValueSet(type, true, set); }
@Override public EquatableValueSet intersect(ValueSet other) { EquatableValueSet otherValueSet = checkCompatibility(other); if (whiteList && otherValueSet.isWhiteList()) { return new EquatableValueSet(type, true, intersect(entries, otherValueSet.entries)); } else if (whiteList) { return new EquatableValueSet(type, true, subtract(entries, otherValueSet.entries)); } else if (otherValueSet.isWhiteList()) { return new EquatableValueSet(type, true, subtract(otherValueSet.entries, entries)); } else { return new EquatableValueSet(type, false, union(otherValueSet.entries, entries)); } }
@Override public EquatableValueSet union(ValueSet other) { EquatableValueSet otherValueSet = checkCompatibility(other); if (whiteList && otherValueSet.isWhiteList()) { return new EquatableValueSet(type, true, union(entries, otherValueSet.entries)); } else if (whiteList) { return new EquatableValueSet(type, false, subtract(otherValueSet.entries, entries)); } else if (otherValueSet.isWhiteList()) { return new EquatableValueSet(type, false, subtract(entries, otherValueSet.entries)); } else { return new EquatableValueSet(type, false, intersect(otherValueSet.entries, entries)); } }