Refine search
private static TextRange toTextRange(Range<Integer> range) { checkState( range.lowerBoundType().equals(BoundType.CLOSED) && range.upperBoundType().equals(BoundType.OPEN)); return new TextRange(range.lowerEndpoint(), range.upperEndpoint()); } }
@Override ContiguousSet<C> subSetImpl( C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) { if (fromElement.compareTo(toElement) == 0 && !fromInclusive && !toInclusive) { // Range would reject our attempt to create (x, x). return new EmptyContiguousSet<C>(domain); } return intersectionInCurrentDomain( Range.range( fromElement, BoundType.forBoolean(fromInclusive), toElement, BoundType.forBoolean(toInclusive))); }
public void testDoublyBoundedAgainstRange() { for (BoundType lboundType : BoundType.values()) { for (BoundType uboundType : BoundType.values()) { Range<Integer> range = Range.range(2, lboundType, 4, uboundType); GeneralRange<Integer> gRange = GeneralRange.range(ORDERING, 2, lboundType, 4, uboundType); for (Integer i : IN_ORDER_VALUES) { assertEquals(i != null && range.contains(i), gRange.contains(i)); } } } }
public static boolean isSingleton(Range<?> range) { boolean result = range.hasLowerBound() && range.hasUpperBound() && range.lowerBoundType().equals(BoundType.CLOSED) && range.upperBoundType().equals(BoundType.CLOSED) && Objects.equals(range.lowerEndpoint(), range.upperEndpoint()); return result; }
public void testSubRangeSet() { ImmutableList.Builder<Range<Integer>> rangesBuilder = ImmutableList.builder(); rangesBuilder.add(Range.<Integer>all()); for (int i = -2; i <= 2; i++) { for (BoundType boundType : BoundType.values()) { rangesBuilder.add(Range.upTo(i, boundType)); rangesBuilder.add(Range.downTo(i, boundType)); for (BoundType lbType : BoundType.values()) { for (BoundType ubType : BoundType.values()) { rangesBuilder.add(Range.range(i, lbType, j, ubType));
private void _writeContents(Range<?> value, JsonGenerator g, SerializerProvider provider) throws IOException { if (value.hasLowerBound()) { if (_endpointSerializer != null) { g.writeFieldName("lowerEndpoint"); _endpointSerializer.serialize(value.lowerEndpoint(), g, provider); } else { provider.defaultSerializeField("lowerEndpoint", value.lowerEndpoint(), g); } // 20-Mar-2016, tatu: Should not use default handling since it leads to // [datatypes-collections#12] with default typing g.writeStringField("lowerBoundType", value.lowerBoundType().name()); } if (value.hasUpperBound()) { if (_endpointSerializer != null) { g.writeFieldName("upperEndpoint"); _endpointSerializer.serialize(value.upperEndpoint(), g, provider); } else { provider.defaultSerializeField("upperEndpoint", value.upperEndpoint(), g); } // same as above; should always be just String so g.writeStringField("upperBoundType", value.upperBoundType().name()); } }
public NamespaceBundle(NamespaceName nsname, Range<Long> keyRange, NamespaceBundleFactory factory) { this.nsname = checkNotNull(nsname); this.keyRange = checkNotNull(keyRange); checkArgument(this.keyRange.lowerBoundType().equals(BoundType.CLOSED), "Invalid hash range. Lower Endpoint has to be inclusive"); checkArgument( (this.keyRange.upperEndpoint().equals(NamespaceBundles.FULL_UPPER_BOUND) && this.keyRange.upperBoundType().equals(BoundType.CLOSED)) || (!this.keyRange.upperEndpoint().equals(NamespaceBundles.FULL_UPPER_BOUND) && this.keyRange.upperBoundType().equals(BoundType.OPEN)), "Invalid hash range. Upper Endpoint should be exclusive unless it is 0xffffffff"); checkArgument(!this.keyRange.isEmpty(), "Cannot create bundle object for an empty key range"); this.factory = checkNotNull(factory); }
switch (range.lowerBoundType()) break; default: throw new AssertionError(range.lowerBoundType().name()); message.append(range.lowerEndpoint()).append(", ").append(range.upperEndpoint()); switch (range.upperBoundType()) break; default: throw new AssertionError(range.upperBoundType().name());
@Override public NavigableMap<Cut<C>, Range<C>> subMap( Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) { return subMap( Range.range( fromKey, BoundType.forBoolean(fromInclusive), toKey, BoundType.forBoolean(toInclusive))); }
@CollectionSize.Require(ZERO) public void testEmptyMultisetNearby() { for (BoundType type : BoundType.values()) { assertNull(sortedMultiset.headMultiset(e0(), type).lastEntry()); assertNull(sortedMultiset.tailMultiset(e0(), type).firstEntry()); } }
@Override ContiguousSet<C> tailSetImpl(C fromElement, boolean inclusive) { return intersectionInCurrentDomain(Range.downTo(fromElement, BoundType.forBoolean(inclusive))); }
@Override ContiguousSet<C> headSetImpl(C toElement, boolean inclusive) { return intersectionInCurrentDomain(Range.upTo(toElement, BoundType.forBoolean(inclusive))); }
public void testAddManyPairs() { for (int aLow = 0; aLow < 6; aLow++) { for (int aHigh = 0; aHigh < 6; aHigh++) { for (BoundType aLowType : BoundType.values()) { for (BoundType aHighType : BoundType.values()) { if ((aLow == aHigh && aLowType == OPEN && aHighType == OPEN) || aLow > aHigh) { continue; } for (int bLow = 0; bLow < 6; bLow++) { for (int bHigh = 0; bHigh < 6; bHigh++) { for (BoundType bLowType : BoundType.values()) { for (BoundType bHighType : BoundType.values()) { if ((bLow == bHigh && bLowType == OPEN && bHighType == OPEN) || bLow > bHigh) { continue; } doPairTest( range(aLow, aLowType, aHigh, aHighType), range(bLow, bLowType, bHigh, bHighType)); } } } } } } } } }
@Override public NavigableSet<E> headSet(E toElement, boolean inclusive) { return new NavigableElementSet<E>( multiset().headMultiset(toElement, BoundType.forBoolean(inclusive))); }
@Override public NavigableSet<E> subSet( E fromElement, boolean fromInclusive, E toElement, boolean toInclusive) { return new NavigableElementSet<E>( multiset() .subMultiset( fromElement, BoundType.forBoolean(fromInclusive), toElement, BoundType.forBoolean(toInclusive))); }
@Override public boolean equals(@Nullable Object obj) { if (obj instanceof GeneralRange) { GeneralRange<?> r = (GeneralRange<?>) obj; return comparator.equals(r.comparator) && hasLowerBound == r.hasLowerBound && hasUpperBound == r.hasUpperBound && getLowerBoundType().equals(r.getLowerBoundType()) && getUpperBoundType().equals(r.getUpperBoundType()) && Objects.equal(getLowerEndpoint(), r.getLowerEndpoint()) && Objects.equal(getUpperEndpoint(), r.getUpperEndpoint()); } return false; }
@Override public NavigableSet<E> tailSet(E fromElement, boolean inclusive) { return new NavigableElementSet<E>( multiset().tailMultiset(fromElement, BoundType.forBoolean(inclusive))); } }
public void testFromRangeOneEnd() { for (BoundType endpointType : BoundType.values()) { assertEquals( GeneralRange.upTo(Ordering.natural(), 3, endpointType), GeneralRange.from(Range.upTo(3, endpointType))); assertEquals( GeneralRange.downTo(Ordering.natural(), 3, endpointType), GeneralRange.from(Range.downTo(3, endpointType))); } }
@Override public NavigableMap<Cut<C>, Range<C>> tailMap(Cut<C> fromKey, boolean inclusive) { return subMap(Range.downTo(fromKey, BoundType.forBoolean(inclusive))); }
@Override public NavigableMap<Cut<C>, Range<C>> headMap(Cut<C> toKey, boolean inclusive) { return subMap(Range.upTo(toKey, BoundType.forBoolean(inclusive))); }