Package com.globalmentor.model
Class Range<T extends java.lang.Comparable<? super T>>
- java.lang.Object
-
- com.globalmentor.model.Range<T>
-
- Type Parameters:
T
- The type of value supported by the range.
- All Implemented Interfaces:
java.lang.Comparable<Range<T>>
public class Range<T extends java.lang.Comparable<? super T>> extends java.lang.Object implements java.lang.Comparable<Range<T>>
Represents a range of comparable values.- Author:
- Garret Wilson
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(Range<T> range)
Compares this object with the specified object for order.boolean
contains(T value)
Determines if this range contains the given value.boolean
equals(java.lang.Object object)
Determines if this object is equal to another object.T
getLowerBound()
T
getUpperBound()
int
hashCode()
java.lang.String
toString()
-
-
-
Method Detail
-
getLowerBound
public T getLowerBound()
- Returns:
- The lower bound of the range, inclusive, or
null
for infinity.
-
getUpperBound
public T getUpperBound()
- Returns:
- The upper bound of the range, inclusive, or
null
for infinity.
-
contains
public boolean contains(T value)
Determines if this range contains the given value.- Parameters:
value
- The value to check.- Returns:
true
if the given value is within this range, inclusive.- Throws:
java.lang.NullPointerException
- if the given value isnull
.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- A unique hash code for the bounds of this range.
-
equals
public boolean equals(java.lang.Object object)
Determines if this object is equal to another object. This method find equality if the object is another range and the lower and upper bounds are equal (including matchingnull
s).- Overrides:
equals
in classjava.lang.Object
-
compareTo
public int compareTo(Range<T> range)
Compares this object with the specified object for order. This implementation determines order based upon the lower bounds and, only if the lower bounds are equal, the upper bound. Infinity is considered to be a lower value for a lower bound and a higher value for an upper bound than a given value for a bound.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string in the form "(X,X)" representing this range.
-
-