Class NumberRange

  • All Implemented Interfaces:
    java.io.Serializable

    @Deprecated(since="2021-04-30")
    public final class NumberRange
    extends Range
    implements java.io.Serializable
    Deprecated.
    Commons Lang 2 is in maintenance mode. Commons Lang 3 should be used instead.

    NumberRange represents an inclusive range of Number objects of the same type.

    Since:
    2.0 (previously in org.apache.commons.lang)
    See Also:
    Serialized Form
    • Constructor Detail

      • NumberRange

        public NumberRange​(java.lang.Number num)
        Deprecated.

        Constructs a new NumberRange using the specified number as both the minimum and maximum in this range.

        Parameters:
        num - the number to use for this range
        Throws:
        java.lang.IllegalArgumentException - if the number is null
        java.lang.IllegalArgumentException - if the number doesn't implement Comparable
        java.lang.IllegalArgumentException - if the number is Double.NaN or Float.NaN
      • NumberRange

        public NumberRange​(java.lang.Number num1,
                           java.lang.Number num2)
        Deprecated.

        Constructs a new NumberRange with the specified minimum and maximum numbers (both inclusive).

        The arguments may be passed in the order (min,max) or (max,min). The getMinimumNumber() and getMaximumNumber() methods will return the correct value.

        This constructor is designed to be used with two Number objects of the same type. If two objects of different types are passed in, an exception is thrown.

        Parameters:
        num1 - first number that defines the edge of the range, inclusive
        num2 - second number that defines the edge of the range, inclusive
        Throws:
        java.lang.IllegalArgumentException - if either number is null
        java.lang.IllegalArgumentException - if the numbers are of different types
        java.lang.IllegalArgumentException - if the numbers don't implement Comparable
    • Method Detail

      • getMinimumNumber

        public java.lang.Number getMinimumNumber()
        Deprecated.

        Returns the minimum number in this range.

        Specified by:
        getMinimumNumber in class Range
        Returns:
        the minimum number in this range
      • getMaximumNumber

        public java.lang.Number getMaximumNumber()
        Deprecated.

        Returns the maximum number in this range.

        Specified by:
        getMaximumNumber in class Range
        Returns:
        the maximum number in this range
      • containsNumber

        public boolean containsNumber​(java.lang.Number number)
        Deprecated.

        Tests whether the specified number occurs within this range.

        null is handled and returns false.

        Specified by:
        containsNumber in class Range
        Parameters:
        number - the number to test, may be null
        Returns:
        true if the specified number occurs within this range
        Throws:
        java.lang.IllegalArgumentException - if the number is of a different type to the range
      • equals

        public boolean equals​(java.lang.Object obj)
        Deprecated.

        Compares this range to another object to test if they are equal.

        .

        To be equal, the class, minimum and maximum must be equal.

        Overrides:
        equals in class Range
        Parameters:
        obj - the reference object with which to compare
        Returns:
        true if this object is equal
      • hashCode

        public int hashCode()
        Deprecated.

        Gets a hashCode for the range.

        Overrides:
        hashCode in class Range
        Returns:
        a hash code value for this object
      • toString

        public java.lang.String toString()
        Deprecated.

        Gets the range as a String.

        The format of the String is 'Range[min,max]'.

        Overrides:
        toString in class Range
        Returns:
        the String representation of this range