本文整理了Java中com.google.common.collect.Range.contains
方法的一些代码示例,展示了Range.contains
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.contains
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:contains
[英]Returns true if value is within the bounds of this range. For example, on the range [0..2), contains(1) returns true, while contains(2)returns false.
[中]如果值在此范围内,则返回true。例如,在范围[0..2]上,contains(1)返回true,而contains(2)返回false。
代码示例来源:origin: google/guava
public boolean contains(K value) {
return range.contains(value);
}
代码示例来源:origin: google/guava
/**
* @deprecated Provided only to satisfy the {@link Predicate} interface; use {@link #contains}
* instead.
*/
@Deprecated
@Override
public boolean apply(C input) {
return contains(input);
}
代码示例来源:origin: google/guava
@Override
public boolean contains(@Nullable Object object) {
if (object == null) {
return false;
}
try {
return range.contains((C) object);
} catch (ClassCastException e) {
return false;
}
}
代码示例来源:origin: google/guava
private static void putModel(Map<Integer, Integer> model, Range<Integer> range, int value) {
for (int i = MIN_BOUND - 1; i <= MAX_BOUND + 1; i++) {
if (range.contains(i)) {
model.put(i, value);
}
}
}
代码示例来源:origin: google/guava
private static void removeModel(Map<Integer, Integer> model, Range<Integer> range) {
for (int i = MIN_BOUND - 1; i <= MAX_BOUND + 1; i++) {
if (range.contains(i)) {
model.remove(i);
}
}
}
}
代码示例来源:origin: google/guava
@Override
public @Nullable Range<C> rangeContaining(C value) {
checkNotNull(value);
Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(Cut.belowValue(value));
if (floorEntry != null && floorEntry.getValue().contains(value)) {
return floorEntry.getValue();
} else {
// TODO(kevinb): revisit this design choice
return null;
}
}
代码示例来源:origin: google/guava
@Override
public Range<C> rangeContaining(C value) {
int index =
SortedLists.binarySearch(
ranges,
Range.<C>lowerBoundFn(),
Cut.belowValue(value),
Ordering.natural(),
ANY_PRESENT,
NEXT_LOWER);
if (index != -1) {
Range<C> range = ranges.get(index);
return range.contains(value) ? range : null;
}
return null;
}
代码示例来源:origin: google/guava
@Override
public @Nullable Entry<Range<K>, V> getEntry(K key) {
int index =
SortedLists.binarySearch(
ranges,
Range.<K>lowerBoundFn(),
Cut.belowValue(key),
KeyPresentBehavior.ANY_PRESENT,
KeyAbsentBehavior.NEXT_LOWER);
if (index == -1) {
return null;
} else {
Range<K> range = ranges.get(index);
return range.contains(key) ? Maps.immutableEntry(range, values.get(index)) : null;
}
}
代码示例来源:origin: google/guava
private static void checkContains(Range<Integer> range) {
assertFalse(range.contains(4));
assertTrue(range.contains(5));
assertTrue(range.contains(7));
assertFalse(range.contains(8));
}
代码示例来源:origin: google/guava
@Override
public @Nullable V get(K key) {
int index =
SortedLists.binarySearch(
ranges,
Range.<K>lowerBoundFn(),
Cut.belowValue(key),
KeyPresentBehavior.ANY_PRESENT,
KeyAbsentBehavior.NEXT_LOWER);
if (index == -1) {
return null;
} else {
Range<K> range = ranges.get(index);
return range.contains(key) ? values.get(index) : null;
}
}
代码示例来源:origin: google/guava
@Override
protected Entry<Cut<C>, Range<C>> computeNext() {
if (!completeRangeItr.hasNext()) {
return endOfData();
}
Range<C> nextRange = completeRangeItr.next();
if (restriction.lowerBound.compareTo(nextRange.upperBound) >= 0) {
return endOfData();
}
nextRange = nextRange.intersection(restriction);
if (lowerBoundWindow.contains(nextRange.lowerBound)) {
return Maps.immutableEntry(nextRange.lowerBound, nextRange);
} else {
return endOfData();
}
}
};
代码示例来源:origin: google/guava
public void testGreaterThan() {
Range<Integer> range = Range.greaterThan(5);
assertFalse(range.contains(5));
assertTrue(range.contains(6));
assertTrue(range.contains(Integer.MAX_VALUE));
assertTrue(range.hasLowerBound());
assertEquals(5, (int) range.lowerEndpoint());
assertEquals(OPEN, range.lowerBoundType());
assertUnboundedAbove(range);
assertFalse(range.isEmpty());
assertEquals("(5..+\u221e)", range.toString());
reserializeAndAssert(range);
}
代码示例来源:origin: google/guava
public void testAtLeast() {
Range<Integer> range = Range.atLeast(6);
assertFalse(range.contains(5));
assertTrue(range.contains(6));
assertTrue(range.contains(Integer.MAX_VALUE));
assertTrue(range.hasLowerBound());
assertEquals(6, (int) range.lowerEndpoint());
assertEquals(CLOSED, range.lowerBoundType());
assertUnboundedAbove(range);
assertFalse(range.isEmpty());
assertEquals("[6..+\u221e)", 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 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 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));
}
}
}
}
代码示例来源:origin: google/guava
public void testAll() {
Range<Integer> range = Range.all();
assertTrue(range.contains(Integer.MIN_VALUE));
assertTrue(range.contains(Integer.MAX_VALUE));
assertUnboundedBelow(range);
assertUnboundedAbove(range);
assertFalse(range.isEmpty());
assertEquals("(-\u221e..+\u221e)", range.toString());
assertSame(range, reserializeAndAssert(range));
assertSame(range, Range.all());
}
代码示例来源: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: 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 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);
}
内容来源于网络,如有侵权,请联系作者删除!