本文整理了Java中com.google.common.collect.Range.open
方法的一些代码示例,展示了Range.open
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.open
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:open
[英]Returns a range that contains all values strictly greater than lower and strictly less than upper.
[中]返回一个范围,其中包含严格大于下限且严格小于上限的所有值。
代码示例来源:origin: google/guava
public void testOpen_invalid() {
try {
Range.open(4, 3);
fail();
} catch (IllegalArgumentException expected) {
}
try {
Range.open(3, 3);
fail();
} catch (IllegalArgumentException expected) {
}
}
代码示例来源:origin: google/guava
public void testAddAll() {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 10));
rangeSet.addAll(Arrays.asList(Range.open(1, 3), Range.closed(5, 8), Range.closed(9, 11)));
assertThat(rangeSet.asRanges()).containsExactly(Range.openClosed(1, 11)).inOrder();
}
代码示例来源: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 testRemoveAll() {
RangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 10));
rangeSet.removeAll(Arrays.asList(Range.open(1, 3), Range.closed(5, 8), Range.closed(9, 11)));
assertThat(rangeSet.asRanges())
.containsExactly(Range.closedOpen(3, 5), Range.open(8, 9))
.inOrder();
}
代码示例来源:origin: google/guava
public void testDifference() {
RangeSet<Integer> expected =
ImmutableRangeSet.<Integer>builder()
.add(Range.openClosed(3, 4))
.add(Range.open(8, 10))
.add(Range.openClosed(15, 17))
.build();
assertThat(RANGE_SET_ONE.difference(RANGE_SET_TWO)).isEqualTo(expected);
}
代码示例来源:origin: google/guava
public void testSubRangeMapClear() {
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> sub = rangeMap.subRangeMap(Range.closed(5, 11));
sub.clear();
assertEquals(
ImmutableMap.of(Range.open(3, 5), 1, Range.closed(12, 16), 3), rangeMap.asMapOfRanges());
}
代码示例来源:origin: google/guava
public void testUnion() {
RangeSet<Integer> expected =
ImmutableRangeSet.<Integer>builder()
.add(Range.openClosed(0, 4))
.add(Range.closedOpen(5, 10))
.add(Range.closedOpen(12, 15))
.add(Range.openClosed(15, 17))
.add(Range.open(19, 20))
.build();
assertThat(RANGE_SET_ONE.union(RANGE_SET_TWO)).isEqualTo(expected);
}
代码示例来源: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);
}
}
代码示例来源:origin: google/guava
public void testGap_connectedAdjacentYieldsEmpty() {
Range<Integer> range = Range.open(3, 4);
assertEquals(Range.closedOpen(4, 4), range.gap(Range.atLeast(4)));
assertEquals(Range.openClosed(3, 3), range.gap(Range.atMost(3)));
}
代码示例来源:origin: google/guava
public void testIntersection() {
ContiguousSet<Integer> set = ContiguousSet.create(Range.closed(1, 3), integers());
assertEquals(
ImmutableSet.of(1, 2, 3),
ContiguousSet.create(Range.open(-1, 4), integers()).intersection(set));
assertEquals(
ImmutableSet.of(1, 2, 3),
set.intersection(ContiguousSet.create(Range.open(-1, 4), integers())));
assertEquals(
ImmutableSet.of(3), set.intersection(ContiguousSet.create(Range.closed(3, 5), integers())));
}
代码示例来源:origin: google/guava
public void testIntersection() {
RangeSet<Integer> expected =
ImmutableRangeSet.<Integer>builder()
.add(Range.closed(2, 3))
.add(Range.open(6, 7))
.add(Range.singleton(8))
.build();
assertThat(RANGE_SET_ONE.intersection(RANGE_SET_TWO)).isEqualTo(expected);
}
代码示例来源:origin: google/guava
public void testIntersection_empty() {
ContiguousSet<Integer> set = ContiguousSet.closed(1, 3);
ContiguousSet<Integer> emptySet = ContiguousSet.closedOpen(2, 2);
assertEquals(ImmutableSet.of(), set.intersection(emptySet));
assertEquals(ImmutableSet.of(), emptySet.intersection(set));
assertEquals(
ImmutableSet.of(),
ContiguousSet.create(Range.closed(-5, -1), integers())
.intersection(ContiguousSet.create(Range.open(3, 64), integers())));
}
代码示例来源:origin: google/guava
public void testFirst() {
assertEquals(1, ContiguousSet.create(Range.closed(1, 3), integers()).first().intValue());
assertEquals(1, ContiguousSet.create(Range.open(0, 4), integers()).first().intValue());
assertEquals(
Integer.MIN_VALUE,
ContiguousSet.create(Range.<Integer>all(), integers()).first().intValue());
}
代码示例来源:origin: google/guava
public void testLast() {
assertEquals(3, ContiguousSet.create(Range.closed(1, 3), integers()).last().intValue());
assertEquals(3, ContiguousSet.create(Range.open(0, 4), integers()).last().intValue());
assertEquals(
Integer.MAX_VALUE,
ContiguousSet.create(Range.<Integer>all(), integers()).last().intValue());
}
代码示例来源:origin: google/guava
public void testMergesConnectedDisjoint() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(1, 4));
rangeSet.add(Range.open(4, 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 testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(Range.class);
tester.testAllPublicStaticMethods(Range.class);
tester.testAllPublicInstanceMethods(Range.all());
tester.testAllPublicInstanceMethods(Range.open(1, 3));
}
}
代码示例来源: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
@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
@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 testEquals() {
new EqualsTester()
.addEqualityGroup(Range.open(1, 5), Range.range(1, OPEN, 5, OPEN))
.addEqualityGroup(Range.greaterThan(2), Range.greaterThan(2))
.addEqualityGroup(Range.all(), Range.all())
.addEqualityGroup("Phil")
.testEquals();
}
内容来源于网络,如有侵权,请联系作者删除!