Class Range<T extends java.lang.Comparable<? super T>>

  • Type Parameters:
    T - The type of value supported by the range.
    All Implemented Interfaces:
    java.lang.Comparable<Range<T>>

    public class Range<T extends java.lang.Comparable<? super T>>
    extends java.lang.Object
    implements java.lang.Comparable<Range<T>>
    Represents a range of comparable values.
    Author:
    Garret Wilson
    • Constructor Summary

      Constructors 
      Constructor Description
      Range​(T lowerBound, T upperBound)
      Creates a range with a lower and upper bound, inclusive.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(Range<T> range)
      Compares this object with the specified object for order.
      boolean contains​(T value)
      Determines if this range contains the given value.
      boolean equals​(java.lang.Object object)
      Determines if this object is equal to another object.
      T getLowerBound()  
      T getUpperBound()  
      int hashCode()  
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • Range

        public Range​(T lowerBound,
                     T upperBound)
        Creates a range with a lower and upper bound, inclusive.
        Parameters:
        lowerBound - The lower bound of the range, inclusive, or null for infinity.
        upperBound - The upper bound of the range, inclusive, or null for infinity.
    • Method Detail

      • getLowerBound

        public T getLowerBound()
        Returns:
        The lower bound of the range, inclusive, or null for infinity.
      • getUpperBound

        public T getUpperBound()
        Returns:
        The upper bound of the range, inclusive, or null for infinity.
      • contains

        public boolean contains​(T value)
        Determines if this range contains the given value.
        Parameters:
        value - The value to check.
        Returns:
        true if the given value is within this range, inclusive.
        Throws:
        java.lang.NullPointerException - if the given value is null.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        A unique hash code for the bounds of this range.
      • equals

        public boolean equals​(java.lang.Object object)
        Determines if this object is equal to another object. This method find equality if the object is another range and the lower and upper bounds are equal (including matching nulls).
        Overrides:
        equals in class java.lang.Object
      • compareTo

        public int compareTo​(Range<T> range)
        Compares this object with the specified object for order. This implementation determines order based upon the lower bounds and, only if the lower bounds are equal, the upper bound. Infinity is considered to be a lower value for a lower bound and a higher value for an upper bound than a given value for a bound.
        Specified by:
        compareTo in interface java.lang.Comparable<T extends java.lang.Comparable<? super T>>
        Parameters:
        range - The object to be compared.
        Returns:
        A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string in the form "(X,X)" representing this range.