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 DiscreteDomain to ContiguousSet#create.
Each end of the range may be bounded or unbounded. If bounded, there is an associated
endpoint value, and the range is considered to be either open (does not include the
endpoint) or closed (includes the endpoint) on that side. With three possibilities on each
side, this yields nine basic types of ranges, enumerated below. (Notation: a square bracket
([ ]) indicates that the range is closed on that side; a parenthesis (( )) means
it is either open or unbounded. The construct {x | statement} is read "the set of all
x such that statement.")
Range Types Notation Definition Factory method (a..b){x | a < x < b}open[a..b]{x | a <= x <= b}closed(a..b]{x | a < x <= b}openClosed[a..b){x | a <= x < b}closedOpen(a..+∞){x | x > a}greaterThan[a..+∞){x | x >= a}atLeast(-∞..b){x | x < b}lessThan(-∞..b]{x | x <= b}atMost(-∞..+∞){x}all
When both endpoints exist, the upper endpoint may not be less than the lower. The endpoints may be equal only if at least one of the bounds is closed:
[a..a] : a singleton range
[a..a); (a..a] : empty ranges; also valid
(a..a) : invalid; an exception will be thrown
compareTo returns zero, not whether equals
returns true.
Comparable<UnrelatedType> is very broken, and will cause
undefined horrible things to happen in Range. For now, the Range API does not
prevent its use, because this would also rule out all ungenerified (pre-JDK1.5) data types.
This may change in the future.
c1 <= c2 <= c3 of type C,
r.contains(c1) && r.contains(c3) implies r.contains(c2)). This means that a
Range<Integer> can never be used to represent, say, "all prime numbers from
1 to 100."
Predicate, a range yields the same result as invoking contains.
a is said to be the maximal range having property
P if, for all ranges b also having property P, a.encloses(b).
Likewise, a is minimal when b.encloses(a) for all b having
property P. See, for example, the definition of intersection.
Range is serializable if it has no bounds, or if each bound is serializable.
See the Guava User Guide article on Range.
| Modifier and Type | Class and Description |
|---|---|
| private static class | Range.
Needed to serialize sorted collections of Ranges. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Range | |
| pack-priv final Cut | |
| private static final long | |
| pack-priv final Cut |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static <C extends Comparable | |
| public boolean | apply(C input)
Implements com. input (Java 8+ users, see notes in the
class documentation above).
|
| public static <C extends Comparable | |
| public static <C extends Comparable | |
| public Range | |
| public static <C extends Comparable | closed(C lower, C upper)
Returns a range that contains all values greater than or equal to |
| public static <C extends Comparable | closedOpen(C lower, C upper)
Returns a range that contains all values greater than or equal to |
| pack-priv static int | |
| public boolean | |
| public boolean | containsAll(Iterable<? extends C> values)
Returns |
| pack-priv static <C extends Comparable | |
| public static <C extends Comparable | |
| public static <C extends Comparable | |
| public boolean | |
| public boolean | equals(Object
the reference object with which to compare. object)Overrides java. Implements com. true if object is a range having the same endpoints and bound types as
this range.
|
| public Range | |
| public static <C extends Comparable | |
| public int | |
| public boolean | |
| public boolean | |
| public Range | intersection(Range<C> connectedRange)
Returns the maximal range enclosed by both this range and |
| public boolean | isConnected(Range<C> other)
Returns |
| public boolean | |
| public static <C extends Comparable | |
| pack-priv Cut | |
| public BoundType | lowerBoundType()
Returns the type of this range's lower bound: |
| public C | |
| public static <C extends Comparable | open(C lower, C upper)
Returns a range that contains all values strictly greater than |
| public static <C extends Comparable | openClosed(C lower, C upper)
Returns a range that contains all values strictly greater than |
| public static <C extends Comparable | |
| pack-priv static <C extends Comparable | |
| pack-priv Object | |
| public static <C extends Comparable | |
| public Range | |
| public String | toString()
Overrides java. "[3..5)" (other examples are
listed in the class documentation).
|
| private static String | |
| pack-priv Cut | |
| public BoundType | upperBoundType()
Returns the type of this range's upper bound: |
| public C | |
| public static <C extends Comparable |
| ALL | back to summary |
|---|---|
| private static final Range<Comparable<T>> ALL | |
| lowerBound | back to summary |
|---|---|
| pack-priv final Cut<C> lowerBound | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| upperBound | back to summary |
|---|---|
| pack-priv final Cut<C> upperBound | |
| Range | back to summary |
|---|---|
| private Range(Cut<C> lowerBound, Cut<C> upperBound) | |
| all | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains every value of type
| |
| apply | back to summary |
|---|---|
| public boolean apply(C input) Implements com. Doc from com. Returns the result of applying this predicate to
| |
| atLeast | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values greater than or equal to
| |
| atMost | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values less than or equal to
| |
| canonical | back to summary |
|---|---|
| public Range Returns the canonical form of this range in the given domain. The canonical form has the following properties:
Furthermore, this method guarantees that the range returned will be one of the following canonical forms:
| |
| closed | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values greater than or equal to
| |
| closedOpen | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values greater than or equal to
| |
| compareOrThrow | back to summary |
|---|---|
pack-priv static int compareOrThrow(Comparable<T> left, Comparable<T> right)
| |
| contains | back to summary |
|---|---|
| public boolean contains(C value) Returns | |
| containsAll | back to summary |
|---|---|
| public boolean containsAll(Iterable<? extends C> values) Returns | |
| create | back to summary |
|---|---|
| pack-priv static <C extends Comparable | |
| downTo | back to summary |
|---|---|
| public static <C extends Comparable Returns a range from the given endpoint, which may be either inclusive (closed) or exclusive (open), with no upper bound.
| |
| encloseAll | back to summary |
|---|---|
| public static <C extends Comparable Returns the minimal range that contains all of the given values. The returned range is closed on both ends.
| |
| encloses | back to summary |
|---|---|
| public boolean encloses(Range<C> other) Returns
Note that if Being reflexive, antisymmetric and transitive, the | |
| equals | back to summary |
|---|---|
| public boolean equals(Object object) Overrides java. Implements com. Returns
| |
| gap | back to summary |
|---|---|
| public Range Returns the maximal range lying between this range and For example, the gap of The gap exists if and only if the two ranges are either disconnected or immediately adjacent (any intersection must be an empty range). The gap operation is commutative.
| |
| greaterThan | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values strictly greater than
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Returns a hash code for this range.
| |
| hasLowerBound | back to summary |
|---|---|
| public boolean hasLowerBound() Returns | |
| hasUpperBound | back to summary |
|---|---|
| public boolean hasUpperBound() Returns | |
| intersection | back to summary |
|---|---|
| public Range Returns the maximal range enclosed by both this range and For example, the intersection of The intersection exists if and only if the two ranges are connected. The intersection operation is commutative, associative and idempotent, and its identity
element is
| |
| isConnected | back to summary |
|---|---|
| public boolean isConnected(Range<C> other) Returns For example,
Note that this range and The connectedness relation is both reflexive and symmetric, but does not form an equivalence relation as it is not transitive. Note that certain discrete ranges are not considered connected, even though there are no
elements "between them." For example, | |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns Note that certain discrete ranges such as the integer range | |
| lessThan | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values strictly less than
| |
| lowerBound | back to summary |
|---|---|
| pack-priv Cut | |
| lowerBoundType | back to summary |
|---|---|
| public BoundType lowerBoundType() Returns the type of this range's lower bound:
| |
| lowerEndpoint | back to summary |
|---|---|
| public C lowerEndpoint() Returns the lower endpoint of this range.
| |
| open | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values strictly greater than
| |
| openClosed | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains all values strictly greater than
| |
| range | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains any value from
| |
| rangeLexOrdering | back to summary |
|---|---|
pack-priv static <C extends Comparable
| |
| readResolve | back to summary |
|---|---|
| pack-priv Object readResolve() | |
| singleton | back to summary |
|---|---|
| public static <C extends Comparable Returns a range that contains only the given value. The returned range is closed on both ends.
| |
| span | back to summary |
|---|---|
| public Range Returns the minimal range that encloses both this range and If the input ranges are connected, the returned range can also be called their union. If they are not, note that the span might contain values that are not contained in either input range. Like | |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Returns a string representation of this range, such as
| |
| toString | back to summary |
|---|---|
| private static String toString(Cut<?> lowerBound, Cut<?> upperBound) | |
| upperBound | back to summary |
|---|---|
| pack-priv Cut | |
| upperBoundType | back to summary |
|---|---|
| public BoundType upperBoundType() Returns the type of this range's upper bound:
| |
| upperEndpoint | back to summary |
|---|---|
| public C upperEndpoint() Returns the upper endpoint of this range.
| |
| upTo | back to summary |
|---|---|
| public static <C extends Comparable Returns a range with no lower bound up to the given endpoint, which may be either inclusive (closed) or exclusive (open).
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv static final Ordering | |
| private static final long |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public int | compare(Range<?>
the first object to be compared. left, Range<?> the second object to be compared. right)Implements abstract com. Implements java. |
| INSTANCE | back to summary |
|---|---|
| pack-priv static final Ordering<?> INSTANCE | |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID | |
| RangeLexOrdering | back to summary |
|---|---|
| private RangeLexOrdering() | |
| compare | back to summary |
|---|---|
| public int compare(Range<?> left, Range<?> right) Implements abstract com. Implements java. Doc from java. Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
The implementor must ensure that
The implementor must also ensure that the relation is transitive:
Finally, the implementor must ensure that | |