Class IntRange

  • All Implemented Interfaces:
    java.io.Serializable

    public final class IntRange
    extends Range
    implements java.io.Serializable

    IntRange represents an inclusive range of ints.

    Since:
    2.0
    Version:
    $Id: IntRange.java 1057072 2011-01-10 01:55:57Z niallp $
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int hashCode
      Cached output hashCode (class is immutable).
      private int max
      The maximum number in this range (inclusive).
      private java.lang.Integer maxObject
      Cached output maxObject (class is immutable).
      private int min
      The minimum number in this range (inclusive).
      private java.lang.Integer minObject
      Cached output minObject (class is immutable).
      private static long serialVersionUID
      Required for serialization support.
      private java.lang.String toString
      Cached output toString (class is immutable).
    • Constructor Summary

      Constructors 
      Constructor Description
      IntRange​(int number)
      Constructs a new IntRange using the specified number as both the minimum and maximum in this range.
      IntRange​(int number1, int number2)
      Constructs a new IntRange with the specified minimum and maximum numbers (both inclusive).
      IntRange​(java.lang.Number number)
      Constructs a new IntRange using the specified number as both the minimum and maximum in this range.
      IntRange​(java.lang.Number number1, java.lang.Number number2)
      Constructs a new IntRange with the specified minimum and maximum numbers (both inclusive).
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean containsInteger​(int value)
      Tests whether the specified int occurs within this range using int comparison.
      boolean containsNumber​(java.lang.Number number)
      Tests whether the specified number occurs within this range using int comparison.
      boolean containsRange​(Range range)
      Tests whether the specified range occurs entirely within this range using int comparison.
      boolean equals​(java.lang.Object obj)
      Compares this range to another object to test if they are equal.
      double getMaximumDouble()
      Gets the maximum number in this range as a double.
      float getMaximumFloat()
      Gets the maximum number in this range as a float.
      int getMaximumInteger()
      Gets the maximum number in this range as a int.
      long getMaximumLong()
      Gets the maximum number in this range as a long.
      java.lang.Number getMaximumNumber()
      Returns the maximum number in this range.
      double getMinimumDouble()
      Gets the minimum number in this range as a double.
      float getMinimumFloat()
      Gets the minimum number in this range as a float.
      int getMinimumInteger()
      Gets the minimum number in this range as a int.
      long getMinimumLong()
      Gets the minimum number in this range as a long.
      java.lang.Number getMinimumNumber()
      Returns the minimum number in this range.
      int hashCode()
      Gets a hashCode for the range.
      boolean overlapsRange​(Range range)
      Tests whether the specified range overlaps with this range using int comparison.
      int[] toArray()
      Returns an array containing all the integer values in the range.
      java.lang.String toString()
      Gets the range as a String.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Required for serialization support.
        See Also:
        Serializable, Constant Field Values
      • min

        private final int min
        The minimum number in this range (inclusive).
      • max

        private final int max
        The maximum number in this range (inclusive).
      • minObject

        private transient java.lang.Integer minObject
        Cached output minObject (class is immutable).
      • maxObject

        private transient java.lang.Integer maxObject
        Cached output maxObject (class is immutable).
      • hashCode

        private transient int hashCode
        Cached output hashCode (class is immutable).
      • toString

        private transient java.lang.String toString
        Cached output toString (class is immutable).
    • Constructor Detail

      • IntRange

        public IntRange​(int number)

        Constructs a new IntRange using 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 IntRange using the specified number as both the minimum and maximum in this range.

        Parameters:
        number - the number to use for this range, must not be null
        Throws:
        java.lang.IllegalArgumentException - if the number is null
      • IntRange

        public IntRange​(int number1,
                        int number2)

        Constructs a new IntRange with 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, inclusive
        number2 - second number that defines the edge of the range, inclusive
      • IntRange

        public IntRange​(java.lang.Number number1,
                        java.lang.Number number2)

        Constructs a new IntRange with 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, inclusive
        number2 - second number that defines the edge of the range, inclusive
        Throws:
        java.lang.IllegalArgumentException - if either number is null
    • Method Detail

      • getMinimumNumber

        public java.lang.Number getMinimumNumber()

        Returns the minimum number in this range.

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

        public long getMinimumLong()

        Gets the minimum number in this range as a long.

        Overrides:
        getMinimumLong in class Range
        Returns:
        the minimum number in this range
      • getMinimumInteger

        public int getMinimumInteger()

        Gets the minimum number in this range as a int.

        Overrides:
        getMinimumInteger in class Range
        Returns:
        the minimum number in this range
      • getMinimumDouble

        public double getMinimumDouble()

        Gets the minimum number in this range as a double.

        Overrides:
        getMinimumDouble in class Range
        Returns:
        the minimum number in this range
      • getMinimumFloat

        public float getMinimumFloat()

        Gets the minimum number in this range as a float.

        Overrides:
        getMinimumFloat in class Range
        Returns:
        the minimum number in this range
      • getMaximumNumber

        public java.lang.Number getMaximumNumber()

        Returns the maximum number in this range.

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

        public long getMaximumLong()

        Gets the maximum number in this range as a long.

        Overrides:
        getMaximumLong in class Range
        Returns:
        the maximum number in this range
      • getMaximumInteger

        public int getMaximumInteger()

        Gets the maximum number in this range as a int.

        Overrides:
        getMaximumInteger in class Range
        Returns:
        the maximum number in this range
      • getMaximumDouble

        public double getMaximumDouble()

        Gets the maximum number in this range as a double.

        Overrides:
        getMaximumDouble in class Range
        Returns:
        the maximum number in this range
      • getMaximumFloat

        public float getMaximumFloat()

        Gets the maximum number in this range as a float.

        Overrides:
        getMaximumFloat in class Range
        Returns:
        the maximum number in this range
      • containsNumber

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

        Tests whether the specified number occurs within this range using int comparison.

        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
      • containsInteger

        public boolean containsInteger​(int value)

        Tests whether the specified int occurs within this range using int comparison.

        This implementation overrides the superclass for performance as it is the most common case.

        Overrides:
        containsInteger in class Range
        Parameters:
        value - the int to test
        Returns:
        true if the specified number occurs within this range by int comparison
      • containsRange

        public boolean containsRange​(Range range)

        Tests whether the specified range occurs entirely within this range using int comparison.

        null is handled and returns false.

        Overrides:
        containsRange in class Range
        Parameters:
        range - the range to test, may be null
        Returns:
        true if 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 int comparison.

        null is handled and returns false.

        Overrides:
        overlapsRange in class Range
        Parameters:
        range - the range to test, may be null
        Returns:
        true if 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.

        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()

        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()

        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
      • 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