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

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

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

Range.singleton介绍

[英]Returns a range that Range#contains(Comparable) only the given value. The returned range is BoundType#CLOSED on both ends.
[中]返回范围#仅包含(可比较)给定值的范围。返回的范围是BoundType#两端闭合。

代码示例

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

@Override
public Range<Long> visitEnforceSingleRow(EnforceSingleRowNode node, Void context)
{
  return Range.singleton(1L);
}

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

@Generates
private static <C extends Comparable<?>> Range<C> generateRange(C freshElement) {
 return Range.singleton(freshElement);
}

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

@Override
public Range<Long> visitValues(ValuesNode node, Void context)
{
  return Range.singleton((long) node.getRows().size());
}

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

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

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

public static boolean isScalar(PlanNode node, Lookup lookup)
{
  return Range.singleton(1L).encloses(extractCardinality(node, lookup));
}

代码示例来源:origin: apache/incubator-druid

private static Range<String> point(String s)
{
 if (s == null) {
  if (NullHandling.sqlCompatible()) {
   // Range.singleton(null) is invalid
   return Range.lessThan("");
  } else {
   // For non-sql compatible case, null and "" are equivalent
   return Range.singleton("");
  }
 }
 return Range.singleton(s);
}

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

@Test
  public void testLimitOnTopOfValues()
  {
    PlanBuilder planBuilder = new PlanBuilder(new PlanNodeIdAllocator(), dummyMetadata());

    assertEquals(
        extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList())))),
        Range.singleton(1L));

    assertEquals(
        extractCardinality(planBuilder.limit(3, planBuilder.values(emptyList(), ImmutableList.of(emptyList(), emptyList(), emptyList(), emptyList())))),
        Range.singleton(3L));
  }
}

代码示例来源:origin: apache/incubator-druid

@Override
public RangeSet<String> getDimensionRangeSet(String dimension)
{
 if (!Objects.equals(getDimension(), dimension) || getExtractionFn() != null) {
  return null;
 }
 RangeSet<String> retSet = TreeRangeSet.create();
 String valueEquivalent = NullHandling.nullToEmptyIfNeeded(value);
 if (valueEquivalent == null) {
  // Case when SQL compatible null handling is enabled
  // Nulls are less than empty String in segments
  retSet.add(Range.lessThan(""));
 } else {
  retSet.add(Range.singleton(valueEquivalent));
 }
 return retSet;
}

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

@Override
 public Set<Integer> create(Object... elements) {
  ImmutableRangeSet.Builder<Integer> builder = ImmutableRangeSet.builder();
  for (Object o : elements) {
   Integer i = (Integer) o;
   builder.add(Range.singleton(i));
  }
  return builder.build().asSet(DiscreteDomain.integers());
 }
}

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

public void testRemovePartSharingLowerBound() {
 TreeRangeSet<Integer> rangeSet = TreeRangeSet.create();
 rangeSet.add(Range.closed(3, 5));
 rangeSet.remove(Range.closedOpen(3, 5));
 testInvariants(rangeSet);
 assertThat(rangeSet.asRanges()).contains(Range.singleton(5));
 assertThat(rangeSet.complement().asRanges())
   .containsExactly(Range.lessThan(5), Range.greaterThan(5))
   .inOrder();
}

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

@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

rangeMap.asMapOfRanges());
sub.putCoalescing(Range.singleton(7), 1);
assertEquals(
  ImmutableMap.of(Range.closed(5, 7), 1, Range.openClosed(7, 10), 2), sub.asMapOfRanges());

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

public void testEmpty() {
 ImmutableRangeSet<Integer> rangeSet = ImmutableRangeSet.of();
 assertThat(rangeSet.asRanges()).isEmpty();
 assertEquals(ImmutableRangeSet.<Integer>all(), rangeSet.complement());
 assertFalse(rangeSet.contains(0));
 assertFalse(rangeSet.intersects(Range.singleton(0)));
 assertFalse(rangeSet.encloses(Range.singleton(0)));
 assertTrue(rangeSet.enclosesAll(rangeSet));
 assertTrue(rangeSet.isEmpty());
}

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

public void testAll() {
 ImmutableRangeSet<Integer> rangeSet = ImmutableRangeSet.all();
 assertThat(rangeSet.asRanges()).contains(Range.<Integer>all());
 assertTrue(rangeSet.contains(0));
 assertTrue(rangeSet.intersects(Range.singleton(0)));
 assertTrue(rangeSet.intersects(Range.<Integer>all()));
 assertTrue(rangeSet.encloses(Range.<Integer>all()));
 assertTrue(rangeSet.enclosesAll(rangeSet));
 assertEquals(ImmutableRangeSet.<Integer>of(), rangeSet.complement());
}

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

相关文章