A range (or "interval") defines the boundaries around a contiguous span of values of some Comparable type; for example, "integers from 1 to 100 inclusive." Note that it is not possible to iterate over these contained values. To do so, pass this range instance and an appropriate
| 110 | |
| 111 | |
| 112 | @GwtCompatible |
| 113 | @SuppressWarnings("rawtypes") |
| 114 | public final class Range<C extends Comparable> implements Predicate<C>, Serializable { |
| 115 | private static final Function<Range, Cut> LOWER_BOUND_FN = new Function<Range, Cut>() { |
| 116 | @Override |
| 117 | public Cut apply(Range range) { |
| 118 | return range.lowerBound; |
| 119 | } |
| 120 | }; |
| 121 | |
| 122 | @SuppressWarnings("unchecked") |
| 123 | static <C extends Comparable<?>> Function<Range<C>, Cut<C>> lowerBoundFn() { |
| 124 | return (Function) LOWER_BOUND_FN; |
| 125 | } |
| 126 | |
| 127 | private static final Function<Range, Cut> UPPER_BOUND_FN = new Function<Range, Cut>() { |
| 128 | @Override |
| 129 | public Cut apply(Range range) { |
| 130 | return range.upperBound; |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | @SuppressWarnings("unchecked") |
| 135 | static <C extends Comparable<?>> Function<Range<C>, Cut<C>> upperBoundFn() { |
| 136 | return (Function) UPPER_BOUND_FN; |
| 137 | } |
| 138 | |
| 139 | |
| 140 | static final Ordering<Range<?>> RANGE_LEX_ORDERING = new RangeLexOrdering(); |
| 141 | |
| 142 | static <C extends Comparable<?>> Range<C> create(Cut<C> lowerBound, Cut<C> upperBound) { |
| 143 | return new Range<C>(lowerBound, upperBound); |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Returns a range that contains all values strictly greater than {@code |
| 148 | * lower} and strictly less than {@code upper}. |
| 149 | * |
| 150 | * @throws IllegalArgumentException if {@code lower} is greater than <i>or |
| 151 | * equal to</i> {@code upper} |
| 152 | * @since 14.0 |
| 153 | */ |
| 154 | |
| 155 | |
| 156 | public static <C extends Comparable<?>> Range<C> open(C lower, C upper) { |
| 157 | return create(Cut.aboveValue(lower), Cut.belowValue(upper)); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Returns a range that contains all values greater than or equal to |
| 162 | * {@code lower} and less than or equal to {@code upper}. |
| 163 | * |
| 164 | * @throws IllegalArgumentException if {@code lower} is greater than {@code |
| 165 | * upper} |
| 166 | * @since 14.0 |
| 167 | */ |
| 168 | |
| 169 |