Class Range<T>
- Type Parameters:
T- the type of values contained in the range
This class is not designed to hold large or "infinite" ranges; it is not stream-based. Instead, you might supply a small representative range of values and specify the range is "infinite" if it is understood that the value pattern repeats indefinitely.
For example, you might generate an infinite powers-of-ten range with the 4 values 1, 10, 100, 1_000.
A range is Iterable, but deliberately does not implement Collection: mutation is not part of its
contract. Use getValues() when list operations are needed.
The range copies its input collection and never mutates or exposes its internal list, but it does not copy the elements themselves. Mutable elements can therefore change this object's observed equality, hash code, and string representation. Elements should be immutable or otherwise safely shared when a range is used concurrently or as a map key or set member.
Ranges are constructed via static methods.
Examples:
Range.ofFiniteValues("a", "b", "c")Range.ofInfiniteValues(1, 10, 100, 1_000, 10_000)Range.emptyFiniteRange()Range.emptyInfiniteRange()
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionGets the empty finite range.Gets the empty infinite range.booleanChecks if this object is equal to another one.Gets the ordered values that comprise this range.inthashCode()A hash code for this object.Gets whether this range is infinite.iterator()Returns an iterator over the values in this range in proper sequence.ofFiniteValues(@NonNull T @NonNull ... values) Provides a finite range for the given values.ofFiniteValues(@NonNull Collection<@NonNull T> values) Provides a finite range for the given values.ofInfiniteValues(@NonNull T @NonNull ... values) Provides an infinite range for the given values.ofInfiniteValues(@NonNull Collection<@NonNull T> values) Provides an infinite range for the given values.toString()Generates aStringrepresentation of this object.Methods inherited from interface Iterable
forEach, spliterator
-
Method Details
-
ofInfiniteValues
Provides an infinite range for the given values.- Type Parameters:
T- the type of values contained in the range- Parameters:
values- the values of the range, not null and containing no null elements- Returns:
- an infinite range, not null
-
ofInfiniteValues
Provides an infinite range for the given values.- Type Parameters:
T- the type of values contained in the range- Parameters:
values- the values of the range, not null and containing no null elements- Returns:
- an infinite range, not null
-
ofFiniteValues
Provides a finite range for the given values.- Type Parameters:
T- the type of values contained in the range- Parameters:
values- the values of the range, not null and containing no null elements- Returns:
- a finite range, not null
-
ofFiniteValues
Provides a finite range for the given values.- Type Parameters:
T- the type of values contained in the range- Parameters:
values- the values of the range, not null and containing no null elements- Returns:
- a finite range, not null
-
emptyFiniteRange
Gets the empty finite range.- Type Parameters:
T- the type of values contained in the range- Returns:
- the empty finite range, not null
-
emptyInfiniteRange
Gets the empty infinite range.- Type Parameters:
T- the type of values contained in the range- Returns:
- the empty infinite range, not null
-
iterator
-
toString
-
equals
-
hashCode
-
getValues
-
isInfinite
Gets whether this range is infinite.- Returns:
- whether this range's pattern repeats indefinitely, not null
- Since:
- 3.0.0
-