public void testEnclosing(RangeSet<Integer> rangeSet) { assertTrue(rangeSet.enclosesAll(ImmutableList.<Range<Integer>>of())); for (Range<Integer> query : QUERY_RANGES) { boolean expectEnclose = false; for (Range<Integer> expectedRange : rangeSet.asRanges()) { if (expectedRange.encloses(query)) { expectEnclose = true; break; } } assertEquals( rangeSet + " was incorrect on encloses(" + query + ")", expectEnclose, rangeSet.encloses(query)); assertEquals( rangeSet + " was incorrect on enclosesAll([" + query + "])", expectEnclose, rangeSet.enclosesAll(ImmutableList.of(query))); } }
/** Check that this space *fully* contains the {@code other} integer space. */ public boolean contains(IntegerSpace other) { return _rangeset.enclosesAll(other._rangeset.asRanges()); }
public void testEnclosing(RangeSet<Integer> rangeSet) { assertTrue(rangeSet.enclosesAll(ImmutableList.<Range<Integer>>of())); for (Range<Integer> query : QUERY_RANGES) { boolean expectEnclose = false; for (Range<Integer> expectedRange : rangeSet.asRanges()) { if (expectedRange.encloses(query)) { expectEnclose = true; break; } } assertEquals(rangeSet + " was incorrect on encloses(" + query + ")", expectEnclose, rangeSet.encloses(query)); assertEquals( rangeSet + " was incorrect on enclosesAll([" + query + "])", expectEnclose, rangeSet.enclosesAll(ImmutableList.of(query))); } }
final RangeConstraint<N> calculateRangeConstraint(final RangeConstraint<N> baseRangeConstraint) { if (ranges == null) { return baseRangeConstraint; } // Run through alternatives and resolve them against the base type final RangeSet<N> baseRangeSet = baseRangeConstraint.getAllowedRanges(); Verify.verify(!baseRangeSet.isEmpty(), "Base type %s does not define constraints", getBaseType()); final Range<N> baseRange = baseRangeSet.span(); final List<ValueRange> resolvedRanges = ensureResolvedRanges(ranges, baseRange); // Next up, ensure the of boundaries match base constraints final RangeSet<N> typedRanges = ensureTypedRanges(resolvedRanges, baseRange.lowerEndpoint().getClass()); // Now verify if new ranges are strict subset of base ranges if (!baseRangeSet.enclosesAll(typedRanges)) { throw new InvalidRangeConstraintException(typedRanges, "Range constraint %s is not a subset of parent constraint %s", typedRanges, baseRangeSet); } return new ResolvedRangeConstraint<>(constraint, typedRanges); }
final RangeConstraint<N> calculateRangeConstraint(final RangeConstraint<N> baseRangeConstraint) { if (ranges == null) { return baseRangeConstraint; } // Run through alternatives and resolve them against the base type final RangeSet<N> baseRangeSet = baseRangeConstraint.getAllowedRanges(); Verify.verify(!baseRangeSet.isEmpty(), "Base type %s does not define constraints", getBaseType()); final Range<N> baseRange = baseRangeSet.span(); final List<ValueRange> resolvedRanges = ensureResolvedRanges(ranges, baseRange); // Next up, ensure the of boundaries match base constraints final RangeSet<N> typedRanges = ensureTypedRanges(resolvedRanges, baseRange.lowerEndpoint().getClass()); // Now verify if new ranges are strict subset of base ranges if (!baseRangeSet.enclosesAll(typedRanges)) { throw new InvalidRangeConstraintException(typedRanges, "Range constraint %s is not a subset of parent constraint %s", typedRanges, baseRangeSet); } return new ResolvedRangeConstraint<>(constraint, typedRanges); }