Class LongRange
- All Implemented Interfaces:
Serializable
LongRange represents an inclusive range of longs.
- Since:
- 2.0
- Version:
- $Id: LongRange.java 1057072 2011-01-10 01:55:57Z niallp $
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLongRange(long number) Constructs a newLongRangeusing the specified number as both the minimum and maximum in this range.LongRange(long number1, long number2) Constructs a newLongRangewith the specified minimum and maximum numbers (both inclusive).Constructs a newLongRangeusing the specified number as both the minimum and maximum in this range.Constructs a newLongRangewith the specified minimum and maximum numbers (both inclusive). -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsLong(long value) Tests whether the specifiedlongoccurs within this range usinglongcomparison.booleancontainsNumber(Number number) Tests whether the specifiednumberoccurs within this range usinglongcomparison.booleancontainsRange(Range range) Tests whether the specified range occurs entirely within this range usinglongcomparison.booleanCompares this range to another object to test if they are equal.doubleGets the maximum number in this range as adouble.floatGets the maximum number in this range as afloat.intGets the maximum number in this range cast to anint.longGets the maximum number in this range as along.Returns the maximum number in this range.doubleGets the minimum number in this range as adouble.floatGets the minimum number in this range as afloat.intGets the minimum number in this range as aint.longGets the minimum number in this range as along.Returns 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 usinglongcomparison.long[]toArray()Returns an array containing all the long values in the range.toString()Gets the range as aString.Methods inherited from class org.apache.commons.lang.math.Range
containsDouble, containsDouble, containsFloat, containsFloat, containsInteger, containsInteger, containsLong
-
Constructor Details
-
LongRange
public LongRange(long number) Constructs a new
LongRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
number- the number to use for this range
-
LongRange
Constructs a new
LongRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
number- the number to use for this range, must not benull- Throws:
IllegalArgumentException- if the number isnull
-
LongRange
public LongRange(long number1, long number2) Constructs a new
LongRangewith the specified minimum and maximum numbers (both inclusive).The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
number1- first number that defines the edge of the range, inclusivenumber2- second number that defines the edge of the range, inclusive
-
LongRange
Constructs a new
LongRangewith the specified minimum and maximum numbers (both inclusive).The arguments may be passed in the order (min,max) or (max,min). The getMinimum and getMaximum methods will return the correct values.
- Parameters:
number1- first number that defines the edge of the range, inclusivenumber2- second number that defines the edge of the range, inclusive- Throws:
IllegalArgumentException- if either number isnull
-
-
Method Details
-
getMinimumNumber
Returns the minimum number in this range.
- Specified by:
getMinimumNumberin classRange- Returns:
- the minimum number in this range
-
getMinimumLong
public long getMinimumLong()Gets the minimum number in this range as a
long.- Overrides:
getMinimumLongin classRange- Returns:
- the minimum number in this range
-
getMinimumInteger
public int getMinimumInteger()Gets the minimum number in this range as a
int.This conversion can lose information for large values.
- Overrides:
getMinimumIntegerin classRange- Returns:
- the minimum number in this range
-
getMinimumDouble
public double getMinimumDouble()Gets the minimum number in this range as a
double.This conversion can lose information for large values.
- Overrides:
getMinimumDoublein classRange- Returns:
- the minimum number in this range
-
getMinimumFloat
public float getMinimumFloat()Gets the minimum number in this range as a
float.This conversion can lose information for large values.
- Overrides:
getMinimumFloatin classRange- Returns:
- the minimum number in this range
-
getMaximumNumber
Returns the maximum number in this range.
- Specified by:
getMaximumNumberin classRange- Returns:
- the maximum number in this range
-
getMaximumLong
public long getMaximumLong()Gets the maximum number in this range as a
long.- Overrides:
getMaximumLongin classRange- Returns:
- the maximum number in this range
-
getMaximumInteger
public int getMaximumInteger()Gets the maximum number in this range cast to an
int.This conversion can lose information for large values.
- Overrides:
getMaximumIntegerin classRange- Returns:
- the maximum number in this range cast to an
int.
-
getMaximumDouble
public double getMaximumDouble()Gets the maximum number in this range as a
double.This conversion can lose information for large values.
- Overrides:
getMaximumDoublein classRange- Returns:
- The maximum number in this range as a
double.
-
getMaximumFloat
public float getMaximumFloat()Gets the maximum number in this range as a
float.This conversion can lose information for large values.
- Overrides:
getMaximumFloatin classRange- Returns:
- The maximum number in this range as a
float.
-
containsNumber
Tests whether the specified
numberoccurs within this range usinglongcomparison.nullis handled and returnsfalse.- Specified by:
containsNumberin classRange- Parameters:
number- the number to test, may benull- Returns:
trueif the specified number occurs within this range
-
containsLong
public boolean containsLong(long value) Tests whether the specified
longoccurs within this range usinglongcomparison.This implementation overrides the superclass for performance as it is the most common case.
- Overrides:
containsLongin classRange- Parameters:
value- the long to test- Returns:
trueif the specified number occurs within this range bylongcomparison
-
containsRange
Tests whether the specified range occurs entirely within this range using
longcomparison.nullis handled and returnsfalse.- Overrides:
containsRangein classRange- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range occurs entirely within this range- Throws:
IllegalArgumentException- if the range is not of this type
-
overlapsRange
Tests whether the specified range overlaps with this range using
longcomparison.nullis handled and returnsfalse.- Overrides:
overlapsRangein classRange- Parameters:
range- the range to test, may benull- Returns:
trueif the specified range overlaps with this range
-
equals
Compares this range to another object to test if they are equal.
.To be equal, the class, minimum and maximum must be equal.
-
hashCode
public int hashCode()Gets a hashCode for the range.
-
toString
Gets the range as a
String.The format of the String is 'Range[min,max]'.
-
toArray
public long[] toArray()Returns an array containing all the long values in the range.
- Returns:
- the
long[]representation of this range - Since:
- 2.4
-