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

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

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

Range.encloses介绍

[英]Returns true if the bounds of other do not extend outside the bounds of this range. Examples:

  • [3..6] encloses [4..5]
  • (3..6) encloses (3..6)
  • [3..6] encloses [4..4) (even though the latter is empty)
  • (3..6] does not enclose [3..6]
  • [4..5] does not enclose (3..6) (even though it contains every value contained by the latter range)
  • [3..6] does not enclose (1..1] (even though it contains every value contained by the latter range)

Note that if a.encloses(b), then b.contains(v) implies a.contains(v), but as the last two examples illustrate, the converse is not always true.

Being reflexive, antisymmetric and transitive, the encloses relation defines a partial order over ranges. There exists a unique Range#all range according to this relation, and also numerous #isEmpty ranges. Enclosure also implies #isConnected.
[中]如果other的边界未超出此范围的边界,则返回true。例如:
*[3..6]附上[4..5]
*(3..6)封闭(3..6)
*[3..6]包含[4..4](即使后者是空的)
*(3..6]没有附上[3..6]
*[4..5]不包含(3..6)(即使它包含后一个范围包含的所有值)
*[3..6]不包含(1..1)(即使它包含后一个范围包含的所有值)
请注意,如果a.封闭(b),那么b.contains(v)意味着a.contains(v),但正如最后两个示例所示,反过来并不总是正确的。
封闭关系是自反的、反对称的和传递的,它定义了范围上的偏序。存在一个唯一的范围#根据这个关系的所有范围,也存在许多#等空范围。封闭也意味着#断开连接。

代码示例

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

@Override
public boolean encloses(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return floorEntry != null && floorEntry.getValue().encloses(range);
}

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

private @Nullable Range<C> rangeEnclosing(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return (floorEntry != null && floorEntry.getValue().encloses(range))
   ? floorEntry.getValue()
   : null;
}

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

@Override
public boolean encloses(Range<C> otherRange) {
 int index =
   SortedLists.binarySearch(
     ranges,
     Range.<C>lowerBoundFn(),
     otherRange.lowerBound,
     Ordering.natural(),
     ANY_PRESENT,
     NEXT_LOWER);
 return index != -1 && ranges.get(index).encloses(otherRange);
}

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

private static boolean isAtMost(PlanNode node, Lookup lookup, long maxCardinality)
{
  return Range.closed(0L, maxCardinality).encloses(extractCardinality(node, lookup));
}

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

@Override
public boolean encloses(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return floorEntry != null && floorEntry.getValue().encloses(range);
}

代码示例来源:origin: wildfly/wildfly

@Override
public boolean encloses(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return floorEntry != null && floorEntry.getValue().encloses(range);
}

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

@NullableDecl
private Range<C> rangeEnclosing(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return (floorEntry != null && floorEntry.getValue().encloses(range))
   ? floorEntry.getValue()
   : null;
}

代码示例来源:origin: wildfly/wildfly

@NullableDecl
private Range<C> rangeEnclosing(Range<C> range) {
 checkNotNull(range);
 Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerBound.floorEntry(range.lowerBound);
 return (floorEntry != null && floorEntry.getValue().encloses(range))
   ? floorEntry.getValue()
   : null;
}

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

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

代码示例来源:origin: wildfly/wildfly

@Override
public boolean encloses(Range<C> otherRange) {
 int index =
   SortedLists.binarySearch(
     ranges,
     Range.<C>lowerBoundFn(),
     otherRange.lowerBound,
     Ordering.natural(),
     ANY_PRESENT,
     NEXT_LOWER);
 return index != -1 && ranges.get(index).encloses(otherRange);
}

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

/** Returns a view of the intersection of this range set with the given range. */
@Override
public ImmutableRangeSet<C> subRangeSet(Range<C> range) {
 if (!isEmpty()) {
  Range<C> span = span();
  if (range.encloses(span)) {
   return this;
  } else if (range.isConnected(span)) {
   return new ImmutableRangeSet<C>(intersectRanges(range));
  }
 }
 return of();
}

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

if (ranges.isEmpty() || range.isEmpty()) {
 return ImmutableList.of();
} else if (range.encloses(span())) {
 return ranges;

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

if (checkNotNull(range).isEmpty()) {
 return ImmutableRangeMap.of();
} else if (ranges.isEmpty() || range.encloses(span())) {
 return this;

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

/**
 * A builder for immutable range maps. Overlapping ranges are prohibited.
 *
 * @since 14.0
 */
public static final class Builder<K extends Comparable<?>, V> {
 private final List<Entry<Range<K>, V>> entries;
 public Builder() {
  this.entries = Lists.newArrayList();
 }
 /**
  * Associates the specified range with the specified value.
  *
  * @throws IllegalArgumentException if {@code range} is empty
  */
 @CanIgnoreReturnValue
 public Builder<K, V> put(Range<K> range, V value) {
  checkNotNull(range);
  checkNotNull(value);
  checkArgument(!range.isEmpty(), "Range must not be empty, but was %s", range);
  entries.add(Maps.immutableEntry(range, value));
  return this;
 }
 /** Copies all associations from the specified range map into this builder. */
 @CanIgnoreReturnValue
 public Builder<K, V> putAll(RangeMap<K, ? extends V> rangeMap) {
  for (Entry<Range<K>, ? extends V> entry : rangeMap.asMapOfRanges().entrySet()) {

代码示例来源:origin: wildfly/wildfly

/** Returns a view of the intersection of this range set with the given range. */
@Override
public ImmutableRangeSet<C> subRangeSet(Range<C> range) {
 if (!isEmpty()) {
  Range<C> span = span();
  if (range.encloses(span)) {
   return this;
  } else if (range.isConnected(span)) {
   return new ImmutableRangeSet<C>(intersectRanges(range));
  }
 }
 return of();
}

代码示例来源:origin: wildfly/wildfly

if (ranges.isEmpty() || range.isEmpty()) {
 return ImmutableList.of();
} else if (range.encloses(span())) {
 return ranges;

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

public void testEnclosing(RangeSet<Integer> rangeSet) {
 assertTrue(rangeSet.enclosesAll(ImmutableList.<Range<Integer>>of()));
 for (Range<Integer> query : QUERY_RANGES) {
  boolean expectEnclose = false;
  for (Range<Integer> expectedRange : rangeSet.asRanges()) {
   if (expectedRange.encloses(query)) {
    expectEnclose = true;
    break;
   }
  }
  assertEquals(
    rangeSet + " was incorrect on encloses(" + query + ")",
    expectEnclose,
    rangeSet.encloses(query));
  assertEquals(
    rangeSet + " was incorrect on enclosesAll([" + query + "])",
    expectEnclose,
    rangeSet.enclosesAll(ImmutableList.of(query)));
 }
}

代码示例来源:origin: checkstyle/checkstyle

public InputIndentationFromGuava2<K, V> subRangeMap1(final Range<K> range) { //indent:2 exp:2
 Range<K> ranges = null; //indent:4 exp:4
 if (checkNotNull(range).isEmpty()) { //indent:4 exp:4
 } else if (ranges.isEmpty() || range.encloses(span())) { //indent:4 exp:4
  return this; //indent:6 exp:6
 } //indent:4 exp:4
 int lowerIndex = SortedLists.binarySearch(); //indent:4 exp:4
 int upperIndex = SortedLists.binarySearch(); //indent:4 exp:4
 if (lowerIndex >= upperIndex) { //indent:4 exp:4
  return null; //indent:6 exp:6
 } //indent:4 exp:4
 final int off = lowerIndex; //indent:4 exp:4
 final int len = upperIndex - lowerIndex; //indent:4 exp:4
 InputIndentationFromGuava2<K, V> outer = null; //indent:4 exp:4
 return outer; //indent:4 exp:4
} //indent:2 exp:2

相关文章