Class IntRange
- java.lang.Object
-
- org.apache.commons.lang.math.Range
-
- org.apache.commons.lang.math.IntRange
-
- All Implemented Interfaces:
java.io.Serializable
public final class IntRange extends Range implements java.io.Serializable
IntRangerepresents an inclusive range ofints.- Since:
- 2.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description IntRange(int number)Constructs a newIntRangeusing the specified number as both the minimum and maximum in this range.IntRange(int number1, int number2)Constructs a newIntRangewith the specified minimum and maximum numbers (both inclusive).IntRange(java.lang.Number number)Constructs a newIntRangeusing the specified number as both the minimum and maximum in this range.IntRange(java.lang.Number number1, java.lang.Number number2)Constructs a newIntRangewith the specified minimum and maximum numbers (both inclusive).
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsInteger(int value)Tests whether the specifiedintoccurs within this range usingintcomparison.booleancontainsNumber(java.lang.Number number)Tests whether the specifiednumberoccurs within this range usingintcomparison.booleancontainsRange(Range range)Tests whether the specified range occurs entirely within this range usingintcomparison.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.java.lang.NumbergetMaximumNumber()Returns 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.java.lang.NumbergetMinimumNumber()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 usingintcomparison.int[]toArray()Returns an array containing all the integer values in the range.java.lang.StringtoString()Gets the range as aString.-
Methods inherited from class org.apache.commons.lang.math.Range
containsDouble, containsDouble, containsFloat, containsFloat, containsInteger, containsLong, containsLong
-
-
-
-
Constructor Detail
-
IntRange
public IntRange(int number)
Constructs a new
IntRangeusing the specified number as both the minimum and maximum in this range.- Parameters:
number- the number to use for this range
-
IntRange
public IntRange(java.lang.Number number)
Constructs a new
IntRangeusing 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:
java.lang.IllegalArgumentException- if the number isnull
-
IntRange
public IntRange(int number1, int number2)Constructs a new
IntRangewith 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
-
IntRange
public IntRange(java.lang.Number number1, java.lang.Number number2)Constructs a new
IntRangewith 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:
java.lang.IllegalArgumentException- if either number isnull
-
-
Method Detail
-
getMinimumNumber
public java.lang.Number 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.- Overrides:
getMinimumIntegerin classRange- Returns:
- the minimum number in this range
-
getMinimumDouble
public double getMinimumDouble()
Gets the minimum number in this range as a
double.- Overrides:
getMinimumDoublein classRange- Returns:
- the minimum number in this range
-
getMinimumFloat
public float getMinimumFloat()
Gets the minimum number in this range as a
float.- Overrides:
getMinimumFloatin classRange- Returns:
- the minimum number in this range
-
getMaximumNumber
public java.lang.Number 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 as a
int.- Overrides:
getMaximumIntegerin classRange- Returns:
- the maximum number in this range
-
getMaximumDouble
public double getMaximumDouble()
Gets the maximum number in this range as a
double.- Overrides:
getMaximumDoublein classRange- Returns:
- the maximum number in this range
-
getMaximumFloat
public float getMaximumFloat()
Gets the maximum number in this range as a
float.- Overrides:
getMaximumFloatin classRange- Returns:
- the maximum number in this range
-
containsNumber
public boolean containsNumber(java.lang.Number number)
Tests whether the specified
numberoccurs within this range usingintcomparison.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
-
containsInteger
public boolean containsInteger(int value)
Tests whether the specified
intoccurs within this range usingintcomparison.This implementation overrides the superclass for performance as it is the most common case.
- Overrides:
containsIntegerin classRange- Parameters:
value- the int to test- Returns:
trueif the specified number occurs within this range byintcomparison
-
containsRange
public boolean containsRange(Range range)
Tests whether the specified range occurs entirely within this range using
intcomparison.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:
java.lang.IllegalArgumentException- if the range is not of this type
-
overlapsRange
public boolean overlapsRange(Range range)
Tests whether the specified range overlaps with this range using
intcomparison.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
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.
-
hashCode
public int hashCode()
Gets a hashCode for the range.
-
toString
public java.lang.String toString()
Gets the range as a
String.The format of the String is 'Range[min,max]'.
-
toArray
public int[] toArray()
Returns an array containing all the integer values in the range.
- Returns:
- the
int[]representation of this range - Since:
- 2.4
-
-