本文整理了Java中com.google.common.collect.Range.openClosed
方法的一些代码示例,展示了Range.openClosed
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.openClosed
方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:openClosed
[英]Returns a range that contains all values strictly greater than lower and less than or equal to upper.
[中]返回一个范围,该范围包含严格大于下限且小于或等于上限的所有值。
代码示例来源:origin: google/guava
@Override
protected SortedSet<Integer> create(Integer[] elements) {
SortedSet<Integer> set = nullCheckedTreeSet(elements);
if (set.isEmpty()) {
/*
* The (tooLow + 1, tooHigh) arguments below would be invalid because tooLow would be
* greater than tooHigh.
*/
return ContiguousSet.create(Range.openClosed(0, 1), DiscreteDomain.integers()).subSet(0, 1);
}
int tooHigh = set.last() + 1;
int tooLow = set.first() - 1;
set.add(tooHigh);
set.add(tooLow);
return checkedCreate(set).subSet(tooLow + 1, tooHigh);
}
}
代码示例来源: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 testRemovePartFromBelowLowerBound() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 6));
rangeSet.remove(Range.closed(1, 3));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).containsExactly(Range.openClosed(3, 6));
}
代码示例来源: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 testToImmutableRangeSet() {
Range<Integer> rangeOne = Range.closedOpen(1, 5);
Range<Integer> rangeTwo = Range.openClosed(6, 7);
ImmutableRangeSet<Integer> ranges =
ImmutableRangeSet.copyOf(ImmutableList.of(rangeOne, rangeTwo));
CollectorTester.of(ImmutableRangeSet.<Integer>toImmutableRangeSet())
.expectCollects(ranges, rangeOne, rangeTwo);
}
}
代码示例来源: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 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
public void testCreate_empty() {
assertEquals(ImmutableSet.of(), ContiguousSet.create(Range.closedOpen(1, 1), integers()));
assertEquals(ImmutableSet.of(), ContiguousSet.closedOpen(1, 1));
assertEquals(ImmutableSet.of(), ContiguousSet.create(Range.openClosed(5, 5), integers()));
assertEquals(
ImmutableSet.of(), ContiguousSet.create(Range.lessThan(Integer.MIN_VALUE), integers()));
assertEquals(
ImmutableSet.of(), ContiguousSet.create(Range.greaterThan(Integer.MAX_VALUE), integers()));
}
代码示例来源:origin: google/guava
public void testRemovePartSharingUpperBound() {
TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
rangeSet.add(Range.closed(3, 5));
rangeSet.remove(Range.openClosed(3, 5));
testInvariants(rangeSet);
assertThat(rangeSet.asRanges()).contains(Range.singleton(3));
assertThat(rangeSet.complement().asRanges())
.containsExactly(Range.lessThan(3), Range.greaterThan(3))
.inOrder();
}
代码示例来源:origin: google/guava
public void testContainsAll() {
Range<Integer> range = Range.closed(3, 5);
assertTrue(range.containsAll(asList(3, 3, 4, 5)));
assertFalse(range.containsAll(asList(3, 3, 4, 5, 6)));
// We happen to know that natural-order sorted sets use a different code
// path, so we test that separately
assertTrue(range.containsAll(ImmutableSortedSet.of(3, 3, 4, 5)));
assertTrue(range.containsAll(ImmutableSortedSet.of(3)));
assertTrue(range.containsAll(ImmutableSortedSet.<Integer>of()));
assertFalse(range.containsAll(ImmutableSortedSet.of(3, 3, 4, 5, 6)));
assertTrue(Range.openClosed(3, 3).containsAll(Collections.<Integer>emptySet()));
}
代码示例来源:origin: google/guava
public void testBuilderRejectsEmptyRanges() {
for (int i = MIN_BOUND; i <= MAX_BOUND; i++) {
ImmutableRangeMap.Builder<Integer, Integer> builder = ImmutableRangeMap.builder();
try {
builder.put(Range.closedOpen(i, i), 1);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
// success
}
try {
builder.put(Range.openClosed(i, i), 1);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
}
}
代码示例来源: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 testToImmutableRangeSet() {
Range<Integer> rangeOne = Range.closedOpen(1, 5);
Range<Integer> rangeTwo = Range.openClosed(6, 7);
ImmutableRangeMap<Integer, Integer> rangeMap =
new ImmutableRangeMap.Builder<Integer, Integer>().put(rangeOne, 1).put(rangeTwo, 6).build();
CollectorTester.of(
ImmutableRangeMap.<Range<Integer>, Integer, Integer>toImmutableRangeMap(
k -> k, k -> k.lowerEndpoint()))
.expectCollects(rangeMap, rangeOne, rangeTwo);
}
}
代码示例来源: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 testGap_general() {
Range<Integer> openRange = Range.open(4, 8);
Range<Integer> closedRange = Range.closed(4, 8);
// first range open end, second range open start
assertEquals(Range.closed(2, 4), Range.lessThan(2).gap(openRange));
assertEquals(Range.closed(2, 4), openRange.gap(Range.lessThan(2)));
// first range closed end, second range open start
assertEquals(Range.openClosed(2, 4), Range.atMost(2).gap(openRange));
assertEquals(Range.openClosed(2, 4), openRange.gap(Range.atMost(2)));
// first range open end, second range closed start
assertEquals(Range.closedOpen(2, 4), Range.lessThan(2).gap(closedRange));
assertEquals(Range.closedOpen(2, 4), closedRange.gap(Range.lessThan(2)));
// first range closed end, second range closed start
assertEquals(Range.open(2, 4), Range.atMost(2).gap(closedRange));
assertEquals(Range.open(2, 4), closedRange.gap(Range.atMost(2)));
}
代码示例来源:origin: google/guava
public void testEncloses_closed() {
Range<Integer> range = Range.closed(2, 5);
assertTrue(range.encloses(range));
assertTrue(range.encloses(Range.open(2, 5)));
assertTrue(range.encloses(Range.openClosed(2, 5)));
assertTrue(range.encloses(Range.closedOpen(2, 5)));
assertTrue(range.encloses(Range.closed(3, 5)));
assertTrue(range.encloses(Range.closed(2, 4)));
assertFalse(range.encloses(Range.open(1, 6)));
assertFalse(range.encloses(Range.greaterThan(3)));
assertFalse(range.encloses(Range.lessThan(3)));
assertFalse(range.encloses(Range.atLeast(3)));
assertFalse(range.encloses(Range.atMost(3)));
assertFalse(range.encloses(Range.<Integer>all()));
}
代码示例来源:origin: google/guava
public void testEncloses_open() {
Range<Integer> range = Range.open(2, 5);
assertTrue(range.encloses(range));
assertTrue(range.encloses(Range.open(2, 4)));
assertTrue(range.encloses(Range.open(3, 5)));
assertTrue(range.encloses(Range.closed(3, 4)));
assertFalse(range.encloses(Range.openClosed(2, 5)));
assertFalse(range.encloses(Range.closedOpen(2, 5)));
assertFalse(range.encloses(Range.closed(1, 4)));
assertFalse(range.encloses(Range.closed(3, 6)));
assertFalse(range.encloses(Range.greaterThan(3)));
assertFalse(range.encloses(Range.lessThan(3)));
assertFalse(range.encloses(Range.atLeast(3)));
assertFalse(range.encloses(Range.atMost(3)));
assertFalse(range.encloses(Range.<Integer>all()));
}
代码示例来源: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);
}
代码示例来源:origin: google/guava
public void testEquivalentFactories() {
new EqualsTester()
.addEqualityGroup(Range.all())
.addEqualityGroup(Range.atLeast(1), Range.downTo(1, CLOSED))
.addEqualityGroup(Range.greaterThan(1), Range.downTo(1, OPEN))
.addEqualityGroup(Range.atMost(7), Range.upTo(7, CLOSED))
.addEqualityGroup(Range.lessThan(7), Range.upTo(7, OPEN))
.addEqualityGroup(Range.open(1, 7), Range.range(1, OPEN, 7, OPEN))
.addEqualityGroup(Range.openClosed(1, 7), Range.range(1, OPEN, 7, CLOSED))
.addEqualityGroup(Range.closed(1, 7), Range.range(1, CLOSED, 7, CLOSED))
.addEqualityGroup(Range.closedOpen(1, 7), Range.range(1, CLOSED, 7, OPEN))
.testEquals();
}
}
代码示例来源:origin: google/guava
public void testCanonical() {
assertEquals(Range.closedOpen(1, 5), Range.closed(1, 4).canonical(integers()));
assertEquals(Range.closedOpen(1, 5), Range.open(0, 5).canonical(integers()));
assertEquals(Range.closedOpen(1, 5), Range.closedOpen(1, 5).canonical(integers()));
assertEquals(Range.closedOpen(1, 5), Range.openClosed(0, 4).canonical(integers()));
assertEquals(
Range.closedOpen(Integer.MIN_VALUE, 0),
Range.closedOpen(Integer.MIN_VALUE, 0).canonical(integers()));
assertEquals(Range.closedOpen(Integer.MIN_VALUE, 0), Range.lessThan(0).canonical(integers()));
assertEquals(Range.closedOpen(Integer.MIN_VALUE, 1), Range.atMost(0).canonical(integers()));
assertEquals(Range.atLeast(0), Range.atLeast(0).canonical(integers()));
assertEquals(Range.atLeast(1), Range.greaterThan(0).canonical(integers()));
assertEquals(Range.atLeast(Integer.MIN_VALUE), Range.<Integer>all().canonical(integers()));
}
内容来源于网络,如有侵权,请联系作者删除!