本文整理了Java中com.google.common.collect.Range.closed
方法的一些代码示例,展示了Range.closed
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.closed
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:closed
[英]Returns a range that contains all values greater than or equal to lower and less than or equal to upper.
[中]返回一个范围,该范围包含所有大于或等于下限、小于或等于上限的值。
代码示例来源:origin: google/guava
/**
* Returns a nonempty contiguous set containing all {@code long} values from {@code lower}
* (inclusive) to {@code upper} (inclusive). (These are the same values contained in {@code
* Range.closed(lower, upper)}.)
*
* @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
* @since 23.0
*/
@Beta
public static ContiguousSet<Long> closed(long lower, long upper) {
return create(Range.closed(lower, upper), DiscreteDomain.longs());
}
代码示例来源:origin: google/guava
public void testSubSubRangeMap() {
RangeMap<Integer, Integer> rangeMap = TreeRangeMap.create();
rangeMap.put(Range.open(3, 7), 1);
rangeMap.put(Range.closed(9, 10), 2);
rangeMap.put(Range.closed(12, 16), 3);
RangeMap<Integer, Integer> sub1 = rangeMap.subRangeMap(Range.closed(5, 11));
assertEquals(
ImmutableMap.of(Range.closedOpen(5, 7), 1, Range.closed(9, 10), 2), sub1.asMapOfRanges());
RangeMap<Integer, Integer> sub2 = sub1.subRangeMap(Range.open(6, 15));
assertEquals(
ImmutableMap.of(Range.open(6, 7), 1, Range.closed(9, 10), 2), sub2.asMapOfRanges());
}
代码示例来源:origin: google/guava
public void testEncloseAll() {
assertEquals(Range.closed(0, 0), Range.encloseAll(Arrays.asList(0)));
assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(5, -3)));
assertEquals(Range.closed(-3, 5), Range.encloseAll(Arrays.asList(1, 2, 2, 2, 5, -3, 0, -1)));
}
代码示例来源:origin: google/guava
public void testIsConnected() {
assertTrue(Range.closed(3, 5).isConnected(Range.open(5, 6)));
assertTrue(Range.closed(3, 5).isConnected(Range.openClosed(5, 5)));
assertTrue(Range.open(3, 5).isConnected(Range.closed(5, 6)));
assertTrue(Range.closed(3, 7).isConnected(Range.open(6, 8)));
assertTrue(Range.open(3, 7).isConnected(Range.closed(5, 6)));
assertFalse(Range.closed(3, 5).isConnected(Range.closed(7, 8)));
assertFalse(Range.closed(3, 5).isConnected(Range.closedOpen(7, 7)));
}
代码示例来源:origin: google/guava
public void testCallWithTimeout_goodCallableWithEnoughTime() throws Exception {
Stopwatch stopwatch = Stopwatch.createStarted();
String result = service.callWithTimeout(GOOD_CALLABLE, ENOUGH_MS, MILLISECONDS);
assertThat(result).isEqualTo(GOOD_CALLABLE_RESULT);
assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(DELAY_MS, ENOUGH_MS));
}
代码示例来源:origin: google/guava
public void testRemoveEmpty() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 6));
rangeSet.remove(Range.closedOpen(3, 3));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).contains(Range.closed(1, 6));
assertThat(rangeSet.complement().asRanges())
.containsExactly(Range.lessThan(1), Range.greaterThan(6))
.inOrder();
}
代码示例来源:origin: google/guava
public void testApply() {
Predicate<Integer> predicate = Range.closed(2, 3);
assertFalse(predicate.apply(1));
assertTrue(predicate.apply(2));
assertTrue(predicate.apply(3));
assertFalse(predicate.apply(4));
}
代码示例来源:origin: google/guava
@Override
public SampleElements<Entry<Range<Integer>, String>> samples() {
return new SampleElements<>(
mapEntry(Range.singleton(0), "banana"),
mapEntry(Range.closedOpen(3, 5), "frisbee"),
mapEntry(Range.atMost(-1), "fruitcake"),
mapEntry(Range.open(10, 15), "elephant"),
mapEntry(Range.closed(20, 22), "umbrella"));
}
代码示例来源:origin: google/guava
public void testAsList() {
ImmutableList<Integer> list = ContiguousSet.create(Range.closed(1, 3), integers()).asList();
for (int i = 0; i < 3; i++) {
assertEquals(i + 1, list.get(i).intValue());
}
assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.iterator()));
assertEquals(ImmutableList.of(1, 2, 3), ImmutableList.copyOf(list.toArray(new Integer[0])));
}
代码示例来源:origin: google/guava
public void testMergesConnectedWithOverlap() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 4));
rangeSet.add(Range.open(2, 6));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).contains(Range.closedOpen(1, 6));
assertThat(rangeSet.complement().asRanges())
.containsExactly(Range.lessThan(1), Range.atLeast(6))
.inOrder();
}
代码示例来源:origin: google/guava
public void testNewProxy_badMethodWithNotEnoughTime() throws Exception {
SampleImpl target = new SampleImpl(9999);
Sample proxy = service.newProxy(target, Sample.class, NOT_ENOUGH_MS, MILLISECONDS);
Stopwatch stopwatch = Stopwatch.createStarted();
try {
proxy.sleepThenThrowException();
fail("no exception thrown");
} catch (UncheckedTimeoutException expected) {
}
assertThat(stopwatch.elapsed(MILLISECONDS)).isIn(Range.closed(NOT_ENOUGH_MS, DELAY_MS * 2));
}
代码示例来源:origin: google/guava
public void testRemoveAllFromAboveUpperBound() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 6));
rangeSet.remove(Range.closed(3, 7));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).isEmpty();
}
代码示例来源:origin: google/guava
public void testRemoveAllExtendingBothDirections() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 6));
rangeSet.remove(Range.closed(2, 7));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).isEmpty();
}
代码示例来源:origin: google/guava
public void testIgnoresEqual() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 6));
rangeSet.add(Range.closed(1, 6));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).contains(Range.closed(1, 6));
assertThat(rangeSet.complement().asRanges())
.containsExactly(Range.lessThan(1), Range.greaterThan(6))
.inOrder();
}
代码示例来源:origin: google/guava
public void testContainsAll() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) {
assertTrue(set.containsAll(subset));
}
for (Set<Integer> subset : Sets.powerSet(ImmutableSet.of(1, 2, 3))) {
assertFalse(set.containsAll(Sets.union(subset, ImmutableSet.of(9))));
}
assertFalse(set.containsAll((Collection<?>) ImmutableSet.of("blah")));
}
代码示例来源:origin: google/guava
public void testSubSet_outOfOrder() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
try {
set.subSet(3, 2);
fail();
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: google/guava
public void testIgnoresSmallerSharingNoBound() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 6));
rangeSet.add(Range.open(2, 4));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).contains(Range.closed(1, 6));
assertThat(rangeSet.complement().asRanges())
.containsExactly(Range.lessThan(1), Range.greaterThan(6))
.inOrder();
}
代码示例来源:origin: google/guava
public void testRangeContaining2() {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 10));
rangeSet.remove(Range.open(5, 7));
assertEquals(Range.closed(3, 5), rangeSet.rangeContaining(5));
assertTrue(rangeSet.contains(5));
assertEquals(Range.closed(7, 10), rangeSet.rangeContaining(8));
assertTrue(rangeSet.contains(8));
assertNull(rangeSet.rangeContaining(6));
assertFalse(rangeSet.contains(6));
}
代码示例来源:origin: google/guava
public void testTailSet() {
ImmutableSortedSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
assertThat(set.tailSet(Integer.MIN_VALUE)).containsExactly(1, 2, 3).inOrder();
assertThat(set.tailSet(1)).containsExactly(1, 2, 3).inOrder();
assertThat(set.tailSet(2)).containsExactly(2, 3).inOrder();
assertThat(set.tailSet(3)).containsExactly(3).inOrder();
assertThat(set.tailSet(Integer.MIN_VALUE, false)).containsExactly(1, 2, 3).inOrder();
assertThat(set.tailSet(1, false)).containsExactly(2, 3).inOrder();
assertThat(set.tailSet(2, false)).containsExactly(3).inOrder();
assertThat(set.tailSet(3, false)).isEmpty();
}
代码示例来源:origin: google/guava
@GwtIncompatible // SerializableTester
public void testSerialization() {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 10));
rangeSet.remove(Range.open(5, 7));
SerializableTester.reserializeAndAssert(rangeSet);
}
}
内容来源于网络,如有侵权,请联系作者删除!