|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.commons.lang3.Range<T>
public final class Range<T>
Range
represents an immutable range of numbers of the same type.
The objects need to either be implementations of java.lang.Comparable
or you need to supply a java.util.Comparator
.
#ThreadSafe#
Method Summary | ||
---|---|---|
static
|
between(T element1,
T element2)
Constructs a new Range with the specified
minimum and maximum values (both inclusive). |
|
static
|
between(T element1,
T element2,
Comparator<T> c)
Constructs a new Range with the specified
minimum and maximum values (both inclusive). |
|
boolean |
contains(T element)
Tests whether the specified element occurs within this range. |
|
boolean |
containsRange(Range<T> range)
Tests whether the specified range occurs entirely within this range. |
|
boolean |
elementAfter(T element)
Tests whether the specified element occurs after this range. |
|
boolean |
elementBefore(T element)
Tests whether the specified element occurs before this range. |
|
int |
elementCompareTo(T element)
Tests where the specified element occurs relative to this range. |
|
boolean |
equals(Object obj)
Compares this range to another object to test if they are equal. |
|
Comparator<T> |
getComparator()
Gets the comparator being used to determine if objects are within the range. |
|
T |
getMaximum()
Gets the maximum value in this range. |
|
T |
getMinimum()
Gets the minimum value in this range. |
|
int |
hashCode()
Gets a hashCode for the range. |
|
static
|
is(T element)
Constructs a new Range using the specified
element as both the minimum and maximum in this range. |
|
static
|
is(T element,
Comparator<T> c)
Constructs a new Range using the specified
element as both the minimum and maximum in this range. |
|
boolean |
isDefaultNaturalOrdering()
Whether or not the Range is using the default natural comparison method to compare elements. |
|
boolean |
overlapsRange(Range<T> range)
Tests whether the specified range overlaps with this range. |
|
String |
toString()
Gets the range as a String . |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static <T extends Comparable<T>> Range<T> is(T element)
Constructs a new 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.
element
- the value to use for this range, must not be null
IllegalArgumentException
- if the value is null
ClassCastException
- if the value is not Comparablepublic static <T extends Comparable<T>> Range<T> between(T element1, T element2)
Constructs a new Range
with the specified
minimum and maximum values (both inclusive).
The range uses the natural ordering of the elements to determine where values lie in the range.
The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
element1
- first value that defines the edge of the range, inclusiveelement2
- second value that defines the edge of the range, inclusive
IllegalArgumentException
- if either value is null
ClassCastException
- if either value is not Comparablepublic static <T> Range<T> is(T element, Comparator<T> c)
Constructs a new Range
using the specified
element as both the minimum and maximum in this range.
The range uses the passed in Comparator
to
determine where values lie in the range.
element
- the value to use for this range, must not be null
c
- comparator to be used
IllegalArgumentException
- if the value is null
public static <T> Range<T> between(T element1, T element2, Comparator<T> c)
Constructs a new Range
with the specified
minimum and maximum values (both inclusive).
The range uses the passed in Comparator
to
determine where values lie in the range.
The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
element1
- first value that defines the edge of the range, inclusiveelement2
- second value that defines the edge of the range, inclusivec
- comparator to be used
IllegalArgumentException
- if either value is null
public T getMinimum()
Gets the minimum value in this range.
public T getMaximum()
Gets the maximum value in this range.
public Comparator<T> getComparator()
Gets the comparator being used to determine if objects are within the range.
public boolean isDefaultNaturalOrdering()
Whether or not the Range is using the default natural comparison method to compare elements.
public boolean contains(T element)
Tests whether the specified element occurs within this range.
null
is handled and returns false
.
element
- the element to test, may be null
true
if the specified element occurs within this rangepublic boolean elementBefore(T element)
Tests whether the specified element occurs before this range.
null
is handled and returns false
.
element
- the element to test, may be null
true
if the specified element occurs before this rangepublic boolean elementAfter(T element)
Tests whether the specified element occurs after this range.
null
is handled and returns false
.
element
- the element to test, may be null
true
if the specified element occurs after this rangepublic int elementCompareTo(T element)
Tests where the specified element occurs relative to this range.
The API is reminiscent of the Comparable interface returning -1
if
the element is before the range, 0
if contained within the range and
1
if the element is after the range.
element
- the element to test
public boolean containsRange(Range<T> range)
Tests whether the specified range occurs entirely within this range.
null
is handled and returns false
.
range
- the range to test, may be null
true
if the specified range occurs entirely within
this range; otherwise, false
IllegalArgumentException
- if the Range
cannot be comparedpublic boolean overlapsRange(Range<T> range)
Tests whether the specified range overlaps with this range.
null
is handled and returns false
.
range
- the range to test, may be null
true
if the specified range overlaps with this
range; otherwise, false
IllegalArgumentException
- if the Range
cannot be comparedpublic boolean equals(Object obj)
Compares this range to another object to test if they are equal.
.To be equal, the class, minimum and maximum must be equal.
equals
in class Object
obj
- the reference object with which to compare
true
if this object is equalpublic int hashCode()
Gets a hashCode for the range.
hashCode
in class Object
public String toString()
Gets the range as a String
.
The format of the String is 'Range[min,max]'.
toString
in class Object
String
representation of this range
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |