Class Range


  • public class Range
    extends java.lang.Object
    Continuous interval in a one-dimensional coordinate system expressed as a lower bound an an upper bound, inclusive.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      int lower
      The range's lower bound, inclusive.
      int upper
      The range's upper bound, inclusive.
    • Constructor Summary

      Constructors 
      Constructor Description
      Range()
      Constructs an empty range with lower and upper both zero.
      Range​(int lower, int upper)
      Constructs a range with a specified lower bound and upper bound.
      Range​(Range range)
      Constructs a range with the lower bound and upper bound of a specified range.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)  
      int hashCode()  
      boolean isEmpty()
      Indicates whether or not this range is empty.
      int length()
      Returns the length of the interval between this range's lower bound and upper bound, or 0 if this range is empty.
      Range set​(int lower, int upper)
      Sets this range to the specified lower bound and upper bound.
      Range set​(Range range)
      Sets this range to the lower bound and upper bound of a specified range.
      Range setEmpty()
      Sets this range to an empty range.
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lower

        public int lower
        The range's lower bound, inclusive.
      • upper

        public int upper
        The range's upper bound, inclusive.
    • Constructor Detail

      • Range

        public Range()
        Constructs an empty range with lower and upper both zero.
      • Range

        public Range​(int lower,
                     int upper)
        Constructs a range with a specified lower bound and upper bound.
        Parameters:
        lower - the lower bound, inclusive
        upper - the upper bound, inclusive
      • Range

        public Range​(Range range)
        Constructs a range with the lower bound and upper bound of a specified range.
        Parameters:
        range - the range specifying the values
        Throws:
        java.lang.IllegalArgumentException - If the range is null
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • length

        public int length()
        Returns the length of the interval between this range's lower bound and upper bound, or 0 if this range is empty.
        Returns:
        the interval length associated with this range
      • set

        public Range set​(int lower,
                         int upper)
        Sets this range to the specified lower bound and upper bound.
        Parameters:
        lower - the new lower bound, inclusive
        upper - the new upper bound, inclusive
        Returns:
        this range set to the specified values
      • set

        public Range set​(Range range)
        Sets this range to the lower bound and upper bound of a specified range.
        Parameters:
        range - the range specifying the new values
        Returns:
        this range with its lower bound and upper bound set to that of the specified range
        Throws:
        java.lang.IllegalArgumentException - If the range is null
      • setEmpty

        public Range setEmpty()
        Sets this range to an empty range.
        Returns:
        this range with its lower bound and upper bound both set to zero
      • isEmpty

        public boolean isEmpty()
        Indicates whether or not this range is empty. An range is empty when its lower bound is greater than or equal to its upper bound.
        Returns:
        true if this range is empty, false otherwise