com.google.common.collect.Range.atLeast()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(132)

本文整理了Java中com.google.common.collect.Range.atLeast方法的一些代码示例,展示了Range.atLeast的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.atLeast方法的具体详情如下:
包路径:com.google.common.collect.Range
类名称:Range
方法名:atLeast

Range.atLeast介绍

[英]Returns a range that contains all values greater than or equal to endpoint.
[中]返回包含所有大于或等于端点的值的范围。

代码示例

代码示例来源:origin: google/guava

/**
 * Returns a range from the given endpoint, which may be either inclusive (closed) or exclusive
 * (open), with no upper bound.
 *
 * @since 14.0
 */
public static <C extends Comparable<?>> Range<C> downTo(C endpoint, BoundType boundType) {
 switch (boundType) {
  case OPEN:
   return greaterThan(endpoint);
  case CLOSED:
   return atLeast(endpoint);
  default:
   throw new AssertionError();
 }
}

代码示例来源:origin: prestodb/presto

@Override
public Range<Long> visitAggregation(AggregationNode node, Void context)
{
  if (node.hasEmptyGroupingSet()) {
    return Range.singleton(1L);
  }
  return Range.atLeast(0L);
}

代码示例来源:origin: google/guava

public void testOrderingCuts() {
 Cut<Integer> a = Range.lessThan(0).lowerBound;
 Cut<Integer> b = Range.atLeast(0).lowerBound;
 Cut<Integer> c = Range.greaterThan(0).lowerBound;
 Cut<Integer> d = Range.atLeast(1).lowerBound;
 Cut<Integer> e = Range.greaterThan(1).lowerBound;
 Cut<Integer> f = Range.greaterThan(1).upperBound;
 Helpers.testCompareToAndEquals(ImmutableList.of(a, b, c, d, e, f));
}

代码示例来源: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 testCanonical_unboundedDomain() {
 assertEquals(Range.lessThan(0), Range.lessThan(0).canonical(UNBOUNDED_DOMAIN));
 assertEquals(Range.lessThan(1), Range.atMost(0).canonical(UNBOUNDED_DOMAIN));
 assertEquals(Range.atLeast(0), Range.atLeast(0).canonical(UNBOUNDED_DOMAIN));
 assertEquals(Range.atLeast(1), Range.greaterThan(0).canonical(UNBOUNDED_DOMAIN));
 assertEquals(Range.all(), Range.<Integer>all().canonical(UNBOUNDED_DOMAIN));
}

代码示例来源: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 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 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 testFillHoleExactly() {
 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
 rangeSet.add(Range.closedOpen(1, 3));
 rangeSet.add(Range.closedOpen(4, 6));
 rangeSet.add(Range.closedOpen(3, 4));
 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 testFillHoleWithOverlap() {
 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
 rangeSet.add(Range.closedOpen(1, 3));
 rangeSet.add(Range.closedOpen(4, 6));
 rangeSet.add(Range.closedOpen(2, 5));
 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 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()));
}

代码示例来源:origin: google/guava

@GwtIncompatible // NavigableSet
 public void testSubSet_unnaturalOrdering() {
  ImmutableSortedSet<Integer> set =
    ImmutableSortedSet.<Integer>reverseOrder().add(2, 4, 6, 8, 10).build();

  try {
   Sets.subSet(set, Range.closed(4, 8));
   fail("IllegalArgumentException expected");
  } catch (IllegalArgumentException expected) {
  }

  // These results are all incorrect, but there's no way (short of iterating over the result)
  // to verify that with an arbitrary ordering or comparator.
  assertEquals(ImmutableSortedSet.of(2, 4), Sets.subSet(set, Range.atLeast(4)));
  assertEquals(ImmutableSortedSet.of(8, 10), Sets.subSet(set, Range.atMost(8)));
  assertEquals(ImmutableSortedSet.of(2, 4, 6, 8, 10), Sets.subSet(set, Range.<Integer>all()));
 }
}

代码示例来源: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 testRange_unboundedRange() {
 assertEquals(
   Range.closed(Integer.MIN_VALUE, Integer.MAX_VALUE),
   ContiguousSet.create(Range.<Integer>all(), integers()).range());
 assertEquals(
   Range.atLeast(Integer.MIN_VALUE),
   ContiguousSet.create(Range.<Integer>all(), integers()).range(CLOSED, OPEN));
 assertEquals(
   Range.all(), ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, OPEN));
 assertEquals(
   Range.atMost(Integer.MAX_VALUE),
   ContiguousSet.create(Range.<Integer>all(), integers()).range(OPEN, CLOSED));
}

代码示例来源:origin: google/guava

public void testMultipleBoundedAboveRanges() {
 ImmutableRangeSet<Integer> rangeSet =
   ImmutableRangeSet.<Integer>builder()
     .add(Range.atMost(0))
     .add(Range.closedOpen(2, 5))
     .build();
 assertThat(rangeSet.asRanges())
   .containsExactly(Range.atMost(0), Range.closedOpen(2, 5))
   .inOrder();
 assertTrue(rangeSet.intersects(Range.closed(2, 4)));
 assertTrue(rangeSet.intersects(Range.open(-5, -2)));
 assertTrue(rangeSet.intersects(Range.closed(1, 8)));
 assertFalse(rangeSet.intersects(Range.singleton(1)));
 assertFalse(rangeSet.intersects(Range.greaterThan(5)));
 assertTrue(rangeSet.encloses(Range.closed(2, 4)));
 assertTrue(rangeSet.encloses(Range.open(-5, -2)));
 assertFalse(rangeSet.encloses(Range.closed(1, 8)));
 assertFalse(rangeSet.encloses(Range.greaterThan(5)));
 RangeSet<Integer> expectedComplement =
   ImmutableRangeSet.<Integer>builder().add(Range.open(0, 2)).add(Range.atLeast(5)).build();
 assertEquals(expectedComplement, rangeSet.complement());
}

代码示例来源:origin: google/guava

public void testIntersection_deFactoEmpty() {
 Range<Integer> range = Range.open(3, 4);
 assertEquals(range, range.intersection(range));
 assertEquals(Range.openClosed(3, 3), range.intersection(Range.atMost(3)));
 assertEquals(Range.closedOpen(4, 4), range.intersection(Range.atLeast(4)));
 try {
  range.intersection(Range.lessThan(3));
  fail();
 } catch (IllegalArgumentException expected) {
 }
 try {
  range.intersection(Range.greaterThan(4));
  fail();
 } catch (IllegalArgumentException expected) {
 }
 range = Range.closed(3, 4);
 assertEquals(Range.openClosed(4, 4), range.intersection(Range.greaterThan(4)));
}

代码示例来源: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

@GwtIncompatible // NavigableSet
public void testSubSet_halfBoundedRange() {
 ImmutableSortedSet<Integer> set = ImmutableSortedSet.of(2, 4, 6, 8, 10);
 ImmutableSortedSet<Integer> empty = ImmutableSortedSet.of();
 assertEquals(set, Sets.subSet(set, Range.atLeast(0)));
 assertEquals(ImmutableSortedSet.of(4, 6, 8, 10), Sets.subSet(set, Range.atLeast(4)));
 assertEquals(ImmutableSortedSet.of(8, 10), Sets.subSet(set, Range.atLeast(7)));
 assertEquals(empty, Sets.subSet(set, Range.atLeast(20)));
 assertEquals(set, Sets.subSet(set, Range.greaterThan(0)));
 assertEquals(ImmutableSortedSet.of(6, 8, 10), Sets.subSet(set, Range.greaterThan(4)));
 assertEquals(ImmutableSortedSet.of(8, 10), Sets.subSet(set, Range.greaterThan(7)));
 assertEquals(empty, Sets.subSet(set, Range.greaterThan(20)));
 assertEquals(empty, Sets.subSet(set, Range.lessThan(0)));
 assertEquals(ImmutableSortedSet.of(2), Sets.subSet(set, Range.lessThan(4)));
 assertEquals(ImmutableSortedSet.of(2, 4, 6), Sets.subSet(set, Range.lessThan(7)));
 assertEquals(set, Sets.subSet(set, Range.lessThan(20)));
 assertEquals(empty, Sets.subSet(set, Range.atMost(0)));
 assertEquals(ImmutableSortedSet.of(2, 4), Sets.subSet(set, Range.atMost(4)));
 assertEquals(ImmutableSortedSet.of(2, 4, 6), Sets.subSet(set, Range.atMost(7)));
 assertEquals(set, Sets.subSet(set, Range.atMost(20)));
}

代码示例来源: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 testSingleBoundedRange() {
 ImmutableRangeSet<Integer> rangeSet = ImmutableRangeSet.of(Range.closedOpen(1, 5));
 assertThat(rangeSet.asRanges()).contains(Range.closedOpen(1, 5));
 assertTrue(rangeSet.intersects(Range.closed(3, 4)));
 assertTrue(rangeSet.intersects(Range.closedOpen(0, 2)));
 assertTrue(rangeSet.intersects(Range.closedOpen(3, 7)));
 assertTrue(rangeSet.intersects(Range.greaterThan(2)));
 assertFalse(rangeSet.intersects(Range.greaterThan(7)));
 assertTrue(rangeSet.encloses(Range.closed(3, 4)));
 assertTrue(rangeSet.encloses(Range.closedOpen(1, 4)));
 assertTrue(rangeSet.encloses(Range.closedOpen(1, 5)));
 assertFalse(rangeSet.encloses(Range.greaterThan(2)));
 assertTrue(rangeSet.contains(3));
 assertFalse(rangeSet.contains(5));
 assertFalse(rangeSet.contains(0));
 RangeSet<Integer> expectedComplement = TreeRangeSet.create();
 expectedComplement.add(Range.lessThan(1));
 expectedComplement.add(Range.atLeast(5));
 assertEquals(expectedComplement, rangeSet.complement());
}

相关文章