本文整理了Java中com.google.common.collect.Range.upperBoundType
方法的一些代码示例,展示了Range.upperBoundType
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.upperBoundType
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:upperBoundType
[英]Returns the type of this range's upper bound: BoundType#CLOSED if the range includes its upper endpoint, BoundType#OPEN if it does not.
[中]
代码示例来源:origin: apache/kylin
public static <C extends Comparable<?>> boolean upperBoundInclusive(Range<C> range) {
if (!range.hasUpperBound()) {
throw new IllegalArgumentException(("This range does not have upper bound" + range));
}
return range.upperBoundType() == BoundType.CLOSED;
}
代码示例来源:origin: google/google-java-format
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());
}
}
代码示例来源:origin: google/guava
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return map.tailMap(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return map.headMap(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
代码示例来源:origin: apache/incubator-druid
private static Range<Long> toLongRange(final Range<BoundValue> range)
{
if (!range.hasUpperBound() && !range.hasLowerBound()) {
return Range.all();
} else if (range.hasUpperBound() && !range.hasLowerBound()) {
return Range.upTo(Long.parseLong(range.upperEndpoint().getValue()), range.upperBoundType());
} else if (!range.hasUpperBound() && range.hasLowerBound()) {
return Range.downTo(Long.parseLong(range.lowerEndpoint().getValue()), range.lowerBoundType());
} else {
return Range.range(
Long.parseLong(range.lowerEndpoint().getValue()), range.lowerBoundType(),
Long.parseLong(range.upperEndpoint().getValue()), range.upperBoundType()
);
}
}
}
代码示例来源:origin: google/guava
range.lowerBoundType() == BoundType.CLOSED,
range.upperEndpoint(),
range.upperBoundType() == BoundType.CLOSED);
} else if (range.hasLowerBound()) {
return set.tailSet(range.lowerEndpoint(), range.lowerBoundType() == BoundType.CLOSED);
} else if (range.hasUpperBound()) {
return set.headSet(range.upperEndpoint(), range.upperBoundType() == BoundType.CLOSED);
代码示例来源:origin: google/guava
/** Converts a Range to a GeneralRange. */
static <T extends Comparable> GeneralRange<T> from(Range<T> range) {
@Nullable T lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null;
BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : OPEN;
@Nullable T upperEndpoint = range.hasUpperBound() ? range.upperEndpoint() : null;
BoundType upperBoundType = range.hasUpperBound() ? range.upperBoundType() : OPEN;
return new GeneralRange<T>(
Ordering.natural(),
range.hasLowerBound(),
lowerEndpoint,
lowerBoundType,
range.hasUpperBound(),
upperEndpoint,
upperBoundType);
}
代码示例来源:origin: apache/incubator-druid
public static List<Interval> toIntervals(final RangeSet<Long> rangeSet)
{
final List<Interval> retVal = new ArrayList<>();
for (Range<Long> range : rangeSet.asRanges()) {
final long start;
final long end;
if (range.hasLowerBound()) {
final long millis = range.lowerEndpoint();
start = millis + (range.lowerBoundType() == BoundType.OPEN ? 1 : 0);
} else {
start = Filtration.eternity().getStartMillis();
}
if (range.hasUpperBound()) {
final long millis = range.upperEndpoint();
end = millis + (range.upperBoundType() == BoundType.OPEN ? 0 : 1);
} else {
end = Filtration.eternity().getEndMillis();
}
retVal.add(Intervals.utc(start, end));
}
return retVal;
}
}
代码示例来源:origin: google/guava
private static void assertUnboundedAbove(Range<Integer> range) {
assertFalse(range.hasUpperBound());
try {
range.upperEndpoint();
fail();
} catch (IllegalStateException expected) {
}
try {
range.upperBoundType();
fail();
} catch (IllegalStateException expected) {
}
}
代码示例来源:origin: google/j2objc
/** Converts a Range to a GeneralRange. */
static <T extends Comparable> GeneralRange<T> from(Range<T> range) {
@NullableDecl T lowerEndpoint = range.hasLowerBound() ? range.lowerEndpoint() : null;
BoundType lowerBoundType = range.hasLowerBound() ? range.lowerBoundType() : OPEN;
@NullableDecl T upperEndpoint = range.hasUpperBound() ? range.upperEndpoint() : null;
BoundType upperBoundType = range.hasUpperBound() ? range.upperBoundType() : OPEN;
return new GeneralRange<T>(
Ordering.natural(),
range.hasLowerBound(),
lowerEndpoint,
lowerBoundType,
range.hasUpperBound(),
upperEndpoint,
upperBoundType);
}
代码示例来源:origin: google/guava
public void testAtMost() {
Range<Integer> range = Range.atMost(4);
assertTrue(range.contains(Integer.MIN_VALUE));
assertTrue(range.contains(4));
assertFalse(range.contains(5));
assertUnboundedBelow(range);
assertTrue(range.hasUpperBound());
assertEquals(4, (int) range.upperEndpoint());
assertEquals(CLOSED, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("(-\u221e..4]", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testLessThan() {
Range<Integer> range = Range.lessThan(5);
assertTrue(range.contains(Integer.MIN_VALUE));
assertTrue(range.contains(4));
assertFalse(range.contains(5));
assertUnboundedBelow(range);
assertTrue(range.hasUpperBound());
assertEquals(5, (int) range.upperEndpoint());
assertEquals(OPEN, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("(-\u221e..5)", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public static void serialize(SerializationStreamWriter writer, Range<?> instance)
throws SerializationException {
if (instance.hasLowerBound()) {
writer.writeBoolean(true);
writer.writeBoolean(instance.lowerBoundType() == BoundType.CLOSED);
writer.writeObject(instance.lowerEndpoint());
} else {
writer.writeBoolean(false);
}
if (instance.hasUpperBound()) {
writer.writeBoolean(true);
writer.writeBoolean(instance.upperBoundType() == BoundType.CLOSED);
writer.writeObject(instance.upperEndpoint());
} else {
writer.writeBoolean(false);
}
}
}
代码示例来源:origin: google/guava
public void testSingleton() {
Range<Integer> range = Range.closed(4, 4);
assertFalse(range.contains(3));
assertTrue(range.contains(4));
assertFalse(range.contains(5));
assertTrue(range.hasLowerBound());
assertEquals(4, (int) range.lowerEndpoint());
assertEquals(CLOSED, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(4, (int) range.upperEndpoint());
assertEquals(CLOSED, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("[4..4]", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: apache/incubator-druid
public static BoundDimFilter toFilter(final BoundRefKey boundRefKey, final Range<BoundValue> range)
{
return new BoundDimFilter(
boundRefKey.getDimension(),
range.hasLowerBound() ? range.lowerEndpoint().getValue() : null,
range.hasUpperBound() ? range.upperEndpoint().getValue() : null,
range.hasLowerBound() && range.lowerBoundType() == BoundType.OPEN,
range.hasUpperBound() && range.upperBoundType() == BoundType.OPEN,
null,
boundRefKey.getExtractionFn(),
boundRefKey.getComparator()
);
}
代码示例来源:origin: google/guava
public void testEmpty2() {
Range<Integer> range = Range.openClosed(4, 4);
assertFalse(range.contains(3));
assertFalse(range.contains(4));
assertFalse(range.contains(5));
assertTrue(range.hasLowerBound());
assertEquals(4, (int) range.lowerEndpoint());
assertEquals(OPEN, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(4, (int) range.upperEndpoint());
assertEquals(CLOSED, range.upperBoundType());
assertTrue(range.isEmpty());
assertEquals("(4..4]", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testEmpty1() {
Range<Integer> range = Range.closedOpen(4, 4);
assertFalse(range.contains(3));
assertFalse(range.contains(4));
assertFalse(range.contains(5));
assertTrue(range.hasLowerBound());
assertEquals(4, (int) range.lowerEndpoint());
assertEquals(CLOSED, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(4, (int) range.upperEndpoint());
assertEquals(OPEN, range.upperBoundType());
assertTrue(range.isEmpty());
assertEquals("[4..4)", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testClosed() {
Range<Integer> range = Range.closed(5, 7);
checkContains(range);
assertTrue(range.hasLowerBound());
assertEquals(5, (int) range.lowerEndpoint());
assertEquals(CLOSED, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(7, (int) range.upperEndpoint());
assertEquals(CLOSED, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("[5..7]", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testOpen() {
Range<Integer> range = Range.open(4, 8);
checkContains(range);
assertTrue(range.hasLowerBound());
assertEquals(4, (int) range.lowerEndpoint());
assertEquals(OPEN, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(8, (int) range.upperEndpoint());
assertEquals(OPEN, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("(4..8)", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testClosedOpen() {
Range<Integer> range = Range.closedOpen(5, 8);
checkContains(range);
assertTrue(range.hasLowerBound());
assertEquals(5, (int) range.lowerEndpoint());
assertEquals(CLOSED, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(8, (int) range.upperEndpoint());
assertEquals(OPEN, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("[5..8)", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testOpenClosed() {
Range<Integer> range = Range.openClosed(4, 7);
checkContains(range);
assertTrue(range.hasLowerBound());
assertEquals(4, (int) range.lowerEndpoint());
assertEquals(OPEN, range.lowerBoundType());
assertTrue(range.hasUpperBound());
assertEquals(7, (int) range.upperEndpoint());
assertEquals(CLOSED, range.upperBoundType());
assertFalse(range.isEmpty());
assertEquals("(4..7]", range.toString());
reserializeAndAssert(range);
}
内容来源于网络,如有侵权,请联系作者删除!