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
| 111 | * @since 10.0 |
| 112 | */ |
| 113 | @GwtCompatible |
| 114 | @SuppressWarnings("rawtypes") |
| 115 | public final class Range<C extends Comparable> implements Predicate<C>, Serializable { |
| 116 | |
| 117 | private static final Function<Range, Cut> LOWER_BOUND_FN = |
| 118 | new Function<Range, Cut>() { |
| 119 | @Override |
| 120 | public Cut apply(Range range) { |
| 121 | return range.lowerBound; |
| 122 | } |
| 123 | }; |
| 124 | |
| 125 | @SuppressWarnings("unchecked") |
| 126 | static <C extends Comparable<?>> Function<Range<C>, Cut<C>> lowerBoundFn() { |
| 127 | return (Function) LOWER_BOUND_FN; |
| 128 | } |
| 129 | |
| 130 | private static final Function<Range, Cut> UPPER_BOUND_FN = |
| 131 | new Function<Range, Cut>() { |
| 132 | @Override |
| 133 | public Cut apply(Range range) { |
| 134 | return range.upperBound; |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | @SuppressWarnings("unchecked") |
| 139 | static <C extends Comparable<?>> Function<Range<C>, Cut<C>> upperBoundFn() { |
| 140 | return (Function) UPPER_BOUND_FN; |
| 141 | } |
| 142 | |
| 143 | static final Ordering<Range<?>> RANGE_LEX_ORDERING = new RangeLexOrdering(); |
| 144 | |
| 145 | static <C extends Comparable<?>> Range<C> create(Cut<C> lowerBound, Cut<C> upperBound) { |
| 146 | return new Range<C>(lowerBound, upperBound); |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * Returns a range that contains all values strictly greater than {@code |
| 151 | * lower} and strictly less than {@code upper}. |
| 152 | * |
| 153 | * @throws IllegalArgumentException if {@code lower} is greater than <i>or |
| 154 | * equal to</i> {@code upper} |
| 155 | * @since 14.0 |
| 156 | */ |
| 157 | public static <C extends Comparable<?>> Range<C> open(C lower, C upper) { |
| 158 | return create(Cut.aboveValue(lower), Cut.belowValue(upper)); |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Returns a range that contains all values greater than or equal to |
| 163 | * {@code lower} and less than or equal to {@code upper}. |
| 164 | * |
| 165 | * @throws IllegalArgumentException if {@code lower} is greater than {@code |
| 166 | * upper} |
| 167 | * @since 14.0 |
| 168 | */ |
| 169 | public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) { |
| 170 | return create(Cut.belowValue(lower), Cut.aboveValue(upper)); |