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

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

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

Range.atMost介绍

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

代码示例

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

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

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

@Override
public Map<Range<Integer>, String> create(Object... elements) {
 RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
 for (Object o : elements) {
  @SuppressWarnings("unchecked")
  Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
  rangeMap.put(entry.getKey(), entry.getValue());
 }
 return rangeMap.subRangeMap(Range.atMost(22)).asDescendingMapOfRanges();
}

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

@Override
public Map<Range<Integer>, String> create(Object... elements) {
 RangeMap<Integer, String> rangeMap = TreeRangeMap.create();
 for (Object o : elements) {
  @SuppressWarnings("unchecked")
  Entry<Range<Integer>, String> entry = (Entry<Range<Integer>, String>) o;
  rangeMap.put(entry.getKey(), entry.getValue());
 }
 return rangeMap.subRangeMap(Range.atMost(22)).asMapOfRanges();
}

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

@Test
public void testCumulativePoolAndMemoryCacheSizeAreLimitedByMemoryClass() {
 final int memoryClassBytes = Math.round(
   harness.getScreenSize() * (harness.bitmapPoolScreens + harness.memoryCacheScreens)
     * harness.sizeMultiplier);
 Shadows.shadowOf(harness.activityManager).setMemoryClass(memoryClassBytes / (1024 * 1024));
 int memoryCacheSize = harness.getCalculator().getMemoryCacheSize();
 int bitmapPoolSize = harness.getCalculator().getBitmapPoolSize();
 assertThat((float) memoryCacheSize + bitmapPoolSize)
   .isIn(Range.atMost(memoryClassBytes * harness.sizeMultiplier));
}

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

@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 testRemoveMiddle() {
 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
 rangeSet.add(Range.atMost(6));
 rangeSet.remove(Range.closedOpen(3, 4));
 testInvariants(rangeSet);
 assertThat(rangeSet.asRanges())
   .containsExactly(Range.lessThan(3), Range.closed(4, 6))
   .inOrder();
 assertThat(rangeSet.complement().asRanges())
   .containsExactly(Range.closedOpen(3, 4), Range.greaterThan(6))
   .inOrder();
}

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

@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 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 testSingleBoundedBelowRange() {
 ImmutableRangeSet<Integer> rangeSet = ImmutableRangeSet.of(Range.greaterThan(2));
 assertThat(rangeSet.asRanges()).contains(Range.greaterThan(2));
 assertTrue(rangeSet.intersects(Range.closed(3, 4)));
 assertTrue(rangeSet.intersects(Range.closedOpen(1, 5)));
 assertFalse(rangeSet.intersects(Range.lessThan(1)));
 assertTrue(rangeSet.intersects(Range.greaterThan(1)));
 assertTrue(rangeSet.intersects(Range.greaterThan(3)));
 assertTrue(rangeSet.encloses(Range.closed(3, 4)));
 assertTrue(rangeSet.encloses(Range.greaterThan(3)));
 assertFalse(rangeSet.encloses(Range.closedOpen(1, 5)));
 assertTrue(rangeSet.contains(3));
 assertTrue(rangeSet.contains(5));
 assertFalse(rangeSet.contains(0));
 assertFalse(rangeSet.contains(2));
 assertEquals(ImmutableRangeSet.of(Range.atMost(2)), rangeSet.complement());
}

代码示例来源: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 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()));
}

相关文章