Class Range
- java.lang.Object
-
- org.apache.commons.lang.math.Range
-
- Direct Known Subclasses:
DoubleRange,FloatRange,IntRange,LongRange,NumberRange
public abstract class Range extends java.lang.ObjectRangerepresents a range of numbers of the same type.Specific subclasses hold the range values as different types. Each subclass should be immutable and
Serializableif possible.- Since:
- 2.0
-
-
Constructor Summary
Constructors Constructor Description Range()Constructs a new range.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleancontainsDouble(double value)Tests whether the specifieddoubleoccurs within this range usingdoublecomparison.booleancontainsDouble(java.lang.Number value)Tests whether the specifiedNumberoccurs within this range usingdoublecomparison..booleancontainsFloat(float value)Tests whether the specifiedfloatoccurs within this range usingfloatcomparison.booleancontainsFloat(java.lang.Number value)Tests whether the specifiedNumberoccurs within this range usingfloatcomparison.booleancontainsInteger(int value)Tests whether the specifiedintoccurs within this range usingintcomparison.booleancontainsInteger(java.lang.Number value)Tests whether the specifiedNumberoccurs within this range usingintcomparison..booleancontainsLong(long value)Tests whether the specifiedlongoccurs within this range usinglongcomparison.booleancontainsLong(java.lang.Number value)Tests whether the specifiedNumberoccurs within this range usinglongcomparison..abstract booleancontainsNumber(java.lang.Number number)Tests whether the specifiedNumberoccurs within this range.booleancontainsRange(Range range)Tests whether the specified range occurs entirely within this range.booleanequals(java.lang.Object obj)Compares this range to another object to test if they are equal.doublegetMaximumDouble()Gets the maximum number in this range as adouble.floatgetMaximumFloat()Gets the maximum number in this range as afloat.intgetMaximumInteger()Gets the maximum number in this range as aint.longgetMaximumLong()Gets the maximum number in this range as along.abstract java.lang.NumbergetMaximumNumber()Gets the maximum number in this range.doublegetMinimumDouble()Gets the minimum number in this range as adouble.floatgetMinimumFloat()Gets the minimum number in this range as afloat.intgetMinimumInteger()Gets the minimum number in this range as aint.longgetMinimumLong()Gets the minimum number in this range as along.abstract java.lang.NumbergetMinimumNumber()Gets the minimum number in this range.inthashCode()Gets a hashCode for the range.booleanoverlapsRange(Range range)Tests whether the specified range overlaps with this range.java.lang.StringtoString()Gets the range as aString.
-
-
-
Method Detail
-
getMinimumNumber
public abstract java.lang.Number getMinimumNumber()
Gets the minimum number in this range.
- Returns:
- the minimum number in this range
-
getMinimumLong
public long getMinimumLong()
Gets the minimum number in this range as a
long.This implementation uses the
getMinimumNumber()method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumInteger
public int getMinimumInteger()
Gets the minimum number in this range as a
int.This implementation uses the
getMinimumNumber()method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumDouble
public double getMinimumDouble()
Gets the minimum number in this range as a
double.This implementation uses the
getMinimumNumber()method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMinimumFloat
public float getMinimumFloat()
Gets the minimum number in this range as a
float.This implementation uses the
getMinimumNumber()method. Subclasses may be able to optimise this.- Returns:
- the minimum number in this range
-
getMaximumNumber
public abstract java.lang.Number getMaximumNumber()
Gets the maximum number in this range.
- Returns:
- the maximum number in this range
-
getMaximumLong
public long getMaximumLong()
Gets the maximum number in this range as a
long.This implementation uses the
getMaximumNumber()method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumInteger
public int getMaximumInteger()
Gets the maximum number in this range as a
int.This implementation uses the
getMaximumNumber()method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumDouble
public double getMaximumDouble()
Gets the maximum number in this range as a
double.This implementation uses the
getMaximumNumber()method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
getMaximumFloat
public float getMaximumFloat()
Gets the maximum number in this range as a
float.This implementation uses the
getMaximumNumber()method. Subclasses may be able to optimise this.- Returns:
- the maximum number in this range
-
containsNumber
public abstract boolean containsNumber(java.lang.Number number)
Tests whether the specified
Numberoccurs within this range.The exact comparison implementation varies by subclass. It is intended that an
intspecific subclass will compare usingintcomparison.nullis handled and returnsfalse.- Parameters:
number- the number to test, may benull- Returns:
trueif the specified number occurs within this range- Throws:
java.lang.IllegalArgumentException- if theNumbercannot be compared
-
containsLong
public boolean containsLong(java.lang.Number value)
Tests whether the specified
Numberoccurs within this range usinglongcomparison..nullis handled and returnsfalse.This implementation forwards to the
containsLong(long)method.- Parameters:
value- the long to test, may benull- Returns:
trueif the specified number occurs within this range bylongcomparison
-
containsLong
public boolean containsLong(long value)
Tests whether the specified
longoccurs within this range usinglongcomparison.This implementation uses the
getMinimumLong()andgetMaximumLong()methods and should be good for most uses.- Parameters:
value- the long to test- Returns:
trueif the specified number occurs within this range bylongcomparison
-
containsInteger
public boolean containsInteger(java.lang.Number value)
Tests whether the specified
Numberoccurs within this range usingintcomparison..nullis handled and returnsfalse.This implementation forwards to the
containsInteger(int)method.- Parameters:
value- the integer to test, may benull- Returns:
trueif the specified number occurs within this range byintcomparison
-
containsInteger
public boolean containsInteger(int value)
Tests whether the specified
intoccurs within this range usingintcomparison.This implementation uses the
getMinimumInteger()andgetMaximumInteger()methods and should be good for most uses.- Parameters:
value- the int to test- Returns:
trueif the specified number occurs within this range byintcomparison
-
containsDouble
public boolean containsDouble(java.lang.Number value)
Tests whether the specified
Numberoccurs within this range usingdoublecomparison..nullis handled and returnsfalse.This implementation forwards to the
containsDouble(double)method.- Parameters:
value- the double to test, may benull- Returns:
trueif the specified number occurs within this range bydoublecomparison
-
containsDouble
public boolean containsDouble(double value)
Tests whether the specified
doubleoccurs within this range usingdoublecomparison.This implementation uses the
getMinimumDouble()andgetMaximumDouble()methods and should be good for most uses.- Parameters:
value- the double to test- Returns:
trueif the specified number occurs within this range bydoublecomparison
-
containsFloat
public boolean containsFloat(java.lang.Number value)
Tests whether the specified
Numberoccurs within this range usingfloatcomparison.nullis handled and returnsfalse.This implementation forwards to the
containsFloat(float)method.- Parameters:
value- the float to test, may benull- Returns:
trueif the specified number occurs within this range byfloatcomparison
-
containsFloat
public boolean containsFloat(float value)
Tests whether the specified
floatoccurs within this range usingfloatcomparison.This implementation uses the
getMinimumFloat()andgetMaximumFloat()methods and should be good for most uses.- Parameters:
value- the float to test- Returns:
trueif the specified number occurs within this range byfloatcomparison
-
containsRange
public boolean containsRange(Range range)
Tests whether the specified range occurs entirely within this range.
The exact comparison implementation varies by subclass. It is intended that an
intspecific subclass will compare usingintcomparison.nullis handled and returnsfalse.This implementation uses the
containsNumber(Number)method. Subclasses may be able to optimise this.- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range occurs entirely within this range; otherwise,false- Throws:
java.lang.IllegalArgumentException- if theRangecannot be compared
-
overlapsRange
public boolean overlapsRange(Range range)
Tests whether the specified range overlaps with this range.
The exact comparison implementation varies by subclass. It is intended that an
intspecific subclass will compare usingintcomparison.nullis handled and returnsfalse.This implementation uses the
containsNumber(Number)andcontainsRange(Range)methods. Subclasses may be able to optimise this.- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range overlaps with this range; otherwise,false- Throws:
java.lang.IllegalArgumentException- if theRangecannot be compared
-
equals
public boolean equals(java.lang.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.
This implementation uses the
getMinimumNumber()andgetMaximumNumber()methods. Subclasses may be able to optimise this.- Overrides:
equalsin classjava.lang.Object- Parameters:
obj- the reference object with which to compare- Returns:
trueif this object is equal
-
hashCode
public int hashCode()
Gets a hashCode for the range.
This implementation uses the
getMinimumNumber()andgetMaximumNumber()methods. Subclasses may be able to optimise this.- Overrides:
hashCodein classjava.lang.Object- Returns:
- a hash code value for this object
-
toString
public java.lang.String toString()
Gets the range as a
String.The format of the String is 'Range[min,max]'.
This implementation uses the
getMinimumNumber()andgetMaximumNumber()methods. Subclasses may be able to optimise this.- Overrides:
toStringin classjava.lang.Object- Returns:
- the
Stringrepresentation of this range
-
-