Class Range<T extends Comparable<T>>

  • Type Parameters:
    T - the type of objects in the range

    public final class Range<T extends Comparable<T>>
    extends Object
    Represents a range of objects, where the bounds are always inclusive and may be null.
    • Method Detail

      • of

        public static <T extends Comparable<T>> Range<T> of​(T lowerBound,
                                                            T upperBound)
        Creates a range with a lower bound and an upper bound.
        Type Parameters:
        T - the type of objects in the range
        Parameters:
        lowerBound - the lower bound of the range
        upperBound - the upper bound of the range
        Returns:
        a range with a lower bound and an upper bound
      • startingAt

        public static <T extends Comparable<T>> Range<T> startingAt​(T lowerBound)
        Creates a range with a lower bound and no upper bound.
        Type Parameters:
        T - the type of objects in the range
        Parameters:
        lowerBound - the lower bound of the range
        Returns:
        a range with a lower bound and no upper bound
      • endingAt

        public static <T extends Comparable<T>> Range<T> endingAt​(T upperBound)
        Creates a range with an upper bound and no lower bound.
        Type Parameters:
        T - the type of objects in the range
        Parameters:
        upperBound - the upper bound of the range
        Returns:
        a range with an upper bound and no lower bound
      • unbounded

        public static <T extends Comparable<T>> Range<T> unbounded()
        Creates a range with no lower bound and no upper bound.
        Type Parameters:
        T - the type of objects in the range
        Returns:
        a range with no lower bound and no upper bound
      • getLowerBound

        public T getLowerBound()
        Returns the lower bound of the range.
        Returns:
        the lower bound of the range
      • hasUpperBound

        public boolean hasUpperBound()
        Indicates of this range has an upper bound.
        Returns:
        true if this range has an upper bound, false otherwise
      • contains

        public boolean contains​(T item)
        Tests if the provided item is contained in this range (i.e. is contained in the bounds or equal to one bound).

        Bounds are inclusive.

        Parameters:
        item - the item to test
        Returns:
        true if the provided item is contained in this range, false otherwise
      • lowerBoundIsUpperThanOrEqualToUpperBound

        public boolean lowerBoundIsUpperThanOrEqualToUpperBound()
        Indicates if the two bounds are defined and the lower bound is upper than or equal to the upper bound.
        Returns:
        true if the two bounds are defined and the lower bound is upper than or equal to the upper bound, false otherwise