Beispiel #1
0
  /**
   * Returns a range that contains any value from {@code lower} to {@code upper}, where each
   * endpoint may be either inclusive (closed) or exclusive (open).
   *
   * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
   */
  public static <C extends Comparable<?>> Range<C> range(
      C lower, BoundType lowerType, C upper, BoundType upperType) {
    checkNotNull(lowerType);
    checkNotNull(upperType);

    Cut<C> lowerBound =
        (lowerType == BoundType.OPEN) ? Cut.aboveValue(lower) : Cut.belowValue(lower);
    Cut<C> upperBound =
        (upperType == BoundType.OPEN) ? Cut.belowValue(upper) : Cut.aboveValue(upper);
    return create(lowerBound, upperBound);
  }
 static {
   List<Cut<Integer>> cutsToTest = Lists.newArrayList();
   for (int i = MIN_BOUND - 1; i <= MAX_BOUND + 1; i++) {
     cutsToTest.add(Cut.belowValue(i));
     cutsToTest.add(Cut.aboveValue(i));
   }
   cutsToTest.add(Cut.<Integer>aboveAll());
   cutsToTest.add(Cut.<Integer>belowAll());
   CUTS_TO_TEST = ImmutableList.copyOf(cutsToTest);
 }
Beispiel #3
0
 @Override
 @Nullable
 public Range<C> rangeContaining(C value) {
   checkNotNull(value);
   Entry<Cut<C>, Range<C>> floorEntry = rangesByLowerCut.floorEntry(Cut.belowValue(value));
   if (floorEntry != null && floorEntry.getValue().contains(value)) {
     return floorEntry.getValue();
   } else {
     // TODO(kevinb): revisit this design choice
     return null;
   }
 }
Beispiel #4
0
 /** Returns a range that contains all values greater than or equal to {@code endpoint}. */
 public static <C extends Comparable<?>> Range<C> atLeast(C endpoint) {
   return create(Cut.belowValue(endpoint), Cut.<C>aboveAll());
 }
Beispiel #5
0
 /** Returns a range that contains all values strictly less than {@code endpoint}. */
 public static <C extends Comparable<?>> Range<C> lessThan(C endpoint) {
   return create(Cut.<C>belowAll(), Cut.belowValue(endpoint));
 }
Beispiel #6
0
 /**
  * Returns a range that contains all values greater than or equal to {@code lower} and strictly
  * less than {@code upper}.
  *
  * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
  */
 public static <C extends Comparable<?>> Range<C> closedOpen(C lower, C upper) {
   return create(Cut.belowValue(lower), Cut.belowValue(upper));
 }