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

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

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

Range.range介绍

[英]Returns a range that contains any value from lower to upper, where each endpoint may be either inclusive (closed) or exclusive (open).
[中]返回一个范围,该范围包含从低到高的任何值,其中每个端点可以是包含的(闭合)或独占的(打开)。

代码示例

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey,
     BoundType.forBoolean(fromInclusive),
     toKey,
     BoundType.forBoolean(toInclusive)));
}

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

@Override
ContiguousSet<C> subSetImpl(
  C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) {
 if (fromElement.compareTo(toElement) == 0 && !fromInclusive && !toInclusive) {
  // Range would reject our attempt to create (x, x).
  return new EmptyContiguousSet<C>(domain);
 }
 return intersectionInCurrentDomain(
   Range.range(
     fromElement, BoundType.forBoolean(fromInclusive),
     toElement, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey,
     BoundType.forBoolean(fromInclusive),
     toKey,
     BoundType.forBoolean(toInclusive)));
}

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

@Override
ContiguousSet<C> subSetImpl(
  C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) {
 if (fromElement.compareTo(toElement) == 0 && !fromInclusive && !toInclusive) {
  // Range would reject our attempt to create (x, x).
  return new EmptyContiguousSet<C>(domain);
 }
 return intersectionInCurrentDomain(
   Range.range(
     fromElement, BoundType.forBoolean(fromInclusive),
     toElement, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
ContiguousSet<C> subSetImpl(
  C fromElement, boolean fromInclusive, C toElement, boolean toInclusive) {
 if (fromElement.compareTo(toElement) == 0 && !fromInclusive && !toInclusive) {
  // Range would reject our attempt to create (x, x).
  return new EmptyContiguousSet<C>(domain);
 }
 return intersectionInCurrentDomain(
   Range.range(
     fromElement, BoundType.forBoolean(fromInclusive),
     toElement, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey, BoundType.forBoolean(fromInclusive),
     toKey, BoundType.forBoolean(toInclusive)));
}

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

@Override
public NavigableMap<Cut<C>, Range<C>> subMap(
  Cut<C> fromKey, boolean fromInclusive, Cut<C> toKey, boolean toInclusive) {
 return subMap(
   Range.range(
     fromKey,
     BoundType.forBoolean(fromInclusive),
     toKey,
     BoundType.forBoolean(toInclusive)));
}

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

public void testFromRangeTwoEnds() {
 for (BoundType lowerType : BoundType.values()) {
  for (BoundType upperType : BoundType.values()) {
   assertEquals(
     GeneralRange.range(Ordering.natural(), 3, lowerType, 4, upperType),
     GeneralRange.from(Range.range(3, lowerType, 4, upperType)));
  }
 }
}

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

public void testDoublyBoundedAgainstRange() {
 for (BoundType lboundType : BoundType.values()) {
  for (BoundType uboundType : BoundType.values()) {
   Range<Integer> range = Range.range(2, lboundType, 4, uboundType);
   GeneralRange<Integer> gRange = GeneralRange.range(ORDERING, 2, lboundType, 4, uboundType);
   for (Integer i : IN_ORDER_VALUES) {
    assertEquals(i != null && range.contains(i), gRange.contains(i));
   }
  }
 }
}

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

public void testAddManyPairs() {
 for (int aLow = 0; aLow < 6; aLow++) {
  for (int aHigh = 0; aHigh < 6; aHigh++) {
   for (BoundType aLowType : BoundType.values()) {
    for (BoundType aHighType : BoundType.values()) {
     if ((aLow == aHigh && aLowType == OPEN && aHighType == OPEN) || aLow > aHigh) {
      continue;
     }
     for (int bLow = 0; bLow < 6; bLow++) {
      for (int bHigh = 0; bHigh < 6; bHigh++) {
       for (BoundType bLowType : BoundType.values()) {
        for (BoundType bHighType : BoundType.values()) {
         if ((bLow == bHigh && bLowType == OPEN && bHighType == OPEN) || bLow > bHigh) {
          continue;
         }
         doPairTest(
           range(aLow, aLowType, aHigh, aHighType),
           range(bLow, bLowType, bHigh, bHighType));
        }
       }
      }
     }
    }
   }
  }
 }
}

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

private static Range<Long> toLongRange(final Range<BoundValue> range)
 {
  if (!range.hasUpperBound() && !range.hasLowerBound()) {
   return Range.all();
  } else if (range.hasUpperBound() && !range.hasLowerBound()) {
   return Range.upTo(Long.parseLong(range.upperEndpoint().getValue()), range.upperBoundType());
  } else if (!range.hasUpperBound() && range.hasLowerBound()) {
   return Range.downTo(Long.parseLong(range.lowerEndpoint().getValue()), range.lowerBoundType());
  } else {
   return Range.range(
     Long.parseLong(range.lowerEndpoint().getValue()), range.lowerBoundType(),
     Long.parseLong(range.upperEndpoint().getValue()), range.upperBoundType()
   );
  }
 }
}

代码示例来源: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 testEquals() {
 new EqualsTester()
   .addEqualityGroup(Range.open(1, 5), Range.range(1, OPEN, 5, OPEN))
   .addEqualityGroup(Range.greaterThan(2), Range.greaterThan(2))
   .addEqualityGroup(Range.all(), Range.all())
   .addEqualityGroup("Phil")
   .testEquals();
}

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

public static Range<BoundValue> toRange(final BoundDimFilter bound)
{
 final BoundValue upper = bound.getUpper() != null ? new BoundValue(bound.getUpper(), bound.getOrdering()) : null;
 final BoundValue lower = bound.getLower() != null ? new BoundValue(bound.getLower(), bound.getOrdering()) : null;
 if (lower == null) {
  return bound.isUpperStrict() ? Range.lessThan(upper) : Range.atMost(upper);
 } else if (upper == null) {
  return bound.isLowerStrict() ? Range.greaterThan(lower) : Range.atLeast(lower);
 } else {
  BoundType lowerBoundType = bound.isLowerStrict() ? BoundType.OPEN : BoundType.CLOSED;
  BoundType upperBoundType = bound.isUpperStrict() ? BoundType.OPEN : BoundType.CLOSED;
  return Range.range(lower, lowerBoundType, upper, upperBoundType);
 }
}

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

for (BoundType lbType : BoundType.values()) {
 for (BoundType ubType : BoundType.values()) {
  rangesBuilder.add(Range.range(i, lbType, j, ubType));

相关文章