@Test public void testComplement() { AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(all.complement(), none); assertEquals(none.complement(), all); }
private AllOrNoneValueSet checkCompatibility(ValueSet other) { if (!getType().equals(other.getType())) { throw new IllegalArgumentException(String.format("Mismatched types: %s vs %s", getType(), other.getType())); } if (!(other instanceof AllOrNoneValueSet)) { throw new IllegalArgumentException(String.format("ValueSet is not a AllOrNoneValueSet: %s", other.getClass())); } return (AllOrNoneValueSet) other; } }
public static PrestoThriftAllOrNoneValueSet fromAllOrNoneValueSet(AllOrNoneValueSet valueSet) { return new PrestoThriftAllOrNoneValueSet(valueSet.isAll()); } }
@Override public ValueSet intersect(ValueSet other) { AllOrNoneValueSet otherValueSet = checkCompatibility(other); return new AllOrNoneValueSet(type, all && otherValueSet.all); }
@Test public void testSubtract() { AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(all.subtract(all), none); assertEquals(all.subtract(none), all); assertEquals(none.subtract(all), none); assertEquals(none.subtract(none), none); }
@Test public void testNone() { AllOrNoneValueSet valueSet = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(valueSet.getType(), HYPER_LOG_LOG); assertTrue(valueSet.isNone()); assertFalse(valueSet.isAll()); assertFalse(valueSet.isSingleValue()); assertFalse(valueSet.containsValue(Slices.EMPTY_SLICE)); try { valueSet.getSingleValue(); fail(); } catch (Exception ignored) { } }
@Test public void testAll() { AllOrNoneValueSet valueSet = AllOrNoneValueSet.all(HYPER_LOG_LOG); assertEquals(valueSet.getType(), HYPER_LOG_LOG); assertFalse(valueSet.isNone()); assertTrue(valueSet.isAll()); assertFalse(valueSet.isSingleValue()); assertTrue(valueSet.containsValue(Slices.EMPTY_SLICE)); try { valueSet.getSingleValue(); fail(); } catch (Exception ignored) { } }
@Test public void testUnion() { AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(all.union(all), all); assertEquals(all.union(none), all); assertEquals(none.union(all), all); assertEquals(none.union(none), none); }
@Test public void testIntersect() { AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(all.intersect(all), all); assertEquals(all.intersect(none), none); assertEquals(none.intersect(all), none); assertEquals(none.intersect(none), none); }
@Test public void testJsonSerialization() throws Exception { TestingTypeManager typeManager = new TestingTypeManager(); ObjectMapper mapper = new ObjectMapperProvider().get() .registerModule(new SimpleModule().addDeserializer(Type.class, new TestingTypeDeserializer(typeManager))); AllOrNoneValueSet all = AllOrNoneValueSet.all(HYPER_LOG_LOG); assertEquals(all, mapper.readValue(mapper.writeValueAsString(all), AllOrNoneValueSet.class)); AllOrNoneValueSet none = AllOrNoneValueSet.none(HYPER_LOG_LOG); assertEquals(none, mapper.readValue(mapper.writeValueAsString(none), AllOrNoneValueSet.class)); } }
static ValueSet none(Type type) { if (type.isOrderable()) { return SortedRangeSet.none(type); } if (type.isComparable()) { return EquatableValueSet.none(type); } return AllOrNoneValueSet.none(type); }
static ValueSet all(Type type) { if (type.isOrderable()) { return SortedRangeSet.all(type); } if (type.isComparable()) { return EquatableValueSet.all(type); } return AllOrNoneValueSet.all(type); }
@Override public ValueSet complement() { return new AllOrNoneValueSet(type, !all); }
@Override public <T> T transform(Function<Ranges, T> rangesFunction, Function<DiscreteValues, T> valuesFunction, Function<AllOrNone, T> allOrNoneFunction) { return allOrNoneFunction.apply(getAllOrNone()); }
@Override public ValueSet union(ValueSet other) { AllOrNoneValueSet otherValueSet = checkCompatibility(other); return new AllOrNoneValueSet(type, all || otherValueSet.all); }
static ValueSet none(Type type) { if (type.isOrderable()) { return SortedRangeSet.none(type); } if (type.isComparable()) { return EquatableValueSet.none(type); } return AllOrNoneValueSet.none(type); }
static ValueSet all(Type type) { if (type.isOrderable()) { return SortedRangeSet.all(type); } if (type.isComparable()) { return EquatableValueSet.all(type); } return AllOrNoneValueSet.all(type); }
static AllOrNoneValueSet none(Type type) { return new AllOrNoneValueSet(type, false); }