MCPcopy
hub / github.com/google/guava / Range

Class Range

guava/src/com/google/common/collect/Range.java:123–733  ·  view source on GitHub ↗

A range (or "interval") defines the <i>boundaries</i> around a contiguous span of values of some {@code Comparable} type; for example, "integers from 1 to 100 inclusive." Note that it is not possible to <i>iterate</i> over these contained values. To do so, pass this range instance and an appropriate

Source from the content-addressed store, hash-verified

121 * @since 10.0
122 */
123@GwtCompatible
124@SuppressWarnings("rawtypes") // https://github.com/google/guava/issues/989
125@Immutable(containerOf = "C")
126public final class Range<C extends Comparable> implements Predicate<C>, Serializable {
127 @SuppressWarnings("unchecked")
128 static <C extends Comparable<?>> Ordering<Range<C>> rangeLexOrdering() {
129 return (Ordering<Range<C>>) RangeLexOrdering.INSTANCE;
130 }
131
132 static <C extends Comparable<?>> Range<C> create(Cut<C> lowerBound, Cut<C> upperBound) {
133 return new Range<>(lowerBound, upperBound);
134 }
135
136 /**
137 * Returns a range that contains all values strictly greater than {@code lower} and strictly less
138 * than {@code upper}.
139 *
140 * @throws IllegalArgumentException if {@code lower} is greater than <i>or equal to</i> {@code
141 * upper}
142 * @throws ClassCastException if {@code lower} and {@code upper} are not mutually comparable
143 * @since 14.0
144 */
145 public static <C extends Comparable<?>> Range<C> open(C lower, C upper) {
146 return create(Cut.aboveValue(lower), Cut.belowValue(upper));
147 }
148
149 /**
150 * Returns a range that contains all values greater than or equal to {@code lower} and less than
151 * or equal to {@code upper}.
152 *
153 * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
154 * @throws ClassCastException if {@code lower} and {@code upper} are not mutually comparable
155 * @since 14.0
156 */
157 public static <C extends Comparable<?>> Range<C> closed(C lower, C upper) {
158 return create(Cut.belowValue(lower), Cut.aboveValue(upper));
159 }
160
161 /**
162 * Returns a range that contains all values greater than or equal to {@code lower} and strictly
163 * less than {@code upper}.
164 *
165 * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
166 * @throws ClassCastException if {@code lower} and {@code upper} are not mutually comparable
167 * @since 14.0
168 */
169 public static <C extends Comparable<?>> Range<C> closedOpen(C lower, C upper) {
170 return create(Cut.belowValue(lower), Cut.belowValue(upper));
171 }
172
173 /**
174 * Returns a range that contains all values strictly greater than {@code lower} and less than or
175 * equal to {@code upper}.
176 *
177 * @throws IllegalArgumentException if {@code lower} is greater than {@code upper}
178 * @throws ClassCastException if {@code lower} and {@code upper} are not mutually comparable
179 * @since 14.0
180 */

Callers

nothing calls this directly

Calls 2

belowAllMethod · 0.95
aboveAllMethod · 0.95

Tested by

no test coverage detected