Class Range<T extends Comparable<? super T>>
- Type Parameters:
T
-
- All Implemented Interfaces:
Immutable
,Serializable
Note: it's copied from Apache Commons Lang developed at The Apache Software Foundation (http://www.apache.org/), or under the Apache License 2.0. The methods copied from other products/frameworks may be modified in this class.
An immutable range of objects from a minimum to maximum point inclusive.
#ThreadSafe# if the objects and comparator are thread-safe
- Since:
- 3.0
- Version:
- $Id: Range.java 1565243 2014-02-06 13:37:12Z sebb $
- See Also:
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<? super T>>
Range<T>closed
(T min, T max) static <T extends Comparable<? super T>>
Range<T>closedOpen
(T min, T max) int
Checks where the specified element occurs relative to this range.boolean
Checks whether the specified element occurs within this range.boolean
containsAll
(Collection<? extends T> c) boolean
containsRange
(Range<T> other) Checks whether this range contains all the elements of the specified range.boolean
Compares this range to another object to test if they are equal.int
hashCode()
Gets a suitable hash code for the range.u.Optional<Range<T>>
intersection
(Range<T> other) Calculate the intersection ofthis
and an overlapping Range.boolean
Checks whether this range is after the specified element.boolean
isAfterRange
(Range<T> other) Checks whether this range is completely after the specified range.boolean
Checks whether this range is before the specified element.boolean
isBeforeRange
(Range<T> other) Checks whether this range is completely before the specified range.boolean
isEmpty()
Checks if is empty.boolean
Checks whether this range starts with the specified element.boolean
isOverlappedBy
(Range<T> other) Checks whether this range is overlapped by the specified range.boolean
isStartedBy
(T element) Checks whether this range starts with the specified element.static <T extends Comparable<? super T>>
Range<T>just
(T element) Obtains a range using the specified element as both the minimum and maximum in this range.Gets the minimum value in this range.static <T extends Comparable<? super T>>
Range<T>open
(T min, T max) static <T extends Comparable<? super T>>
Range<T>openClosed
(T min, T max) Copied from Guava under Apache License v2.0
Returns the minimal range that encloses both this range andother
.toString()
Gets the maximum value in this range.
-
Method Details
-
just
Obtains a range using the specified element as both the minimum and maximum in this range.
The range uses the natural ordering of the elements to determine where values lie in the range.
- Type Parameters:
T
- the type of the elements in this range- Parameters:
element
- the value to use for this range, not null- Returns:
- Throws:
IllegalArgumentException
- if the element is null
-
open
- Type Parameters:
T
-- Parameters:
min
-max
-- Returns:
- Throws:
IllegalArgumentException
- if the 'min' or 'max' is null, or min > max.
-
openClosed
- Type Parameters:
T
-- Parameters:
min
-max
-- Returns:
- Throws:
IllegalArgumentException
- if the 'min' or 'max' is null, or min > max.
-
closedOpen
- Type Parameters:
T
-- Parameters:
min
-max
-- Returns:
- Throws:
IllegalArgumentException
- if the 'min' or 'max' is null, or min > max.
-
closed
- Type Parameters:
T
-- Parameters:
min
-max
-- Returns:
- Throws:
IllegalArgumentException
- if the 'min' or 'max' is null, or min > max.
-
boundType
-
lowerEndpoint
Gets the minimum value in this range.
- Returns:
-
upperEndpoint
Gets the maximum value in this range.
- Returns:
-
contains
Checks whether the specified element occurs within this range.
- Parameters:
element
- the element to check for, null returns false- Returns:
- true if the specified element occurs within this range
-
containsAll
- Parameters:
c
-- Returns:
-
isStartedBy
Checks whether this range starts with the specified element.
- Parameters:
element
- the element to check for, null returns false- Returns:
- true if the specified element occurs within this range
-
isEndedBy
Checks whether this range starts with the specified element.
- Parameters:
element
- the element to check for, null returns false- Returns:
- true if the specified element occurs within this range
-
isAfter
Checks whether this range is after the specified element.
- Parameters:
element
- the element to check for, null returns false- Returns:
- true if this range is entirely after the specified element
-
isBefore
Checks whether this range is before the specified element.
- Parameters:
element
- the element to check for, null returns false- Returns:
- true if this range is entirely before the specified element
-
compareTo
Checks where the specified element occurs relative to this range.
Returns
-1
if this range is before the specified element,1
if the this range is after the specified element, otherwise0
if the specified element is contained in this range.- Parameters:
element
- the element to check for, not null- Returns:
- -1, 0 or +1 depending on the element's location relative to the range
-
containsRange
Checks whether this range contains all the elements of the specified range.
- Parameters:
other
- the range to check, null returns false- Returns:
- true if this range contains the specified range
- Throws:
RuntimeException
- if ranges cannot be compared
-
isAfterRange
Checks whether this range is completely after the specified range.
- Parameters:
other
- the range to check, null returns false- Returns:
- true if this range is completely after the specified range
- Throws:
RuntimeException
- if ranges cannot be compared
-
isBeforeRange
Checks whether this range is completely before the specified range.
- Parameters:
other
- the range to check, null returns false- Returns:
- true if this range is completely before the specified range
- Throws:
RuntimeException
- if ranges cannot be compared
-
isOverlappedBy
Checks whether this range is overlapped by the specified range.
Two ranges overlap if there is at least one element in common.
- Parameters:
other
- the range to test, null returns false- Returns:
- true if the specified range overlaps with this range; otherwise,
false
- Throws:
RuntimeException
- if ranges cannot be compared
-
intersection
Calculate the intersection ofthis
and an overlapping Range.- Parameters:
other
- overlapping Range- Returns:
- range representing the intersection of
this
andother
,this
if equal, orOptional.empty()
if they're not overlapped. - Since:
- 3.0.1
-
span
Copied from Guava under Apache License v2.0
Returns the minimal range that encloses both this range andother
. For example, the span of[1..3]
and(5..7)
is[1..7)
.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
intersection
, this operation is commutative, associative and idempotent. Unlike it, it is always well-defined for any two input ranges.- Parameters:
other
-- Returns:
-
isEmpty
public boolean isEmpty()Checks if is empty.- Returns:
- true, if is empty
-
equals
Compares this range to another object to test if they are equal.
.To be equal, the minimum and maximum values must be equal, which ignores any differences in the comparator.
-
hashCode
public int hashCode()Gets a suitable hash code for the range.
-
toString
-