Class Interval<T extends Comparable<T>>


  • public class Interval<T extends Comparable<T>>
    extends Object
    Generic interval. Hold a couple of values A and B, where A <= B.

    Both bounds are inclusive.

    Value object.

    Since:
    9.0
    Author:
    Leonid Bushuev
    • Field Detail

      • begin

        @NotNull
        public final T extends Comparable<T> begin
        The left bound of the interval.
      • end

        @NotNull
        public final T extends Comparable<T> end
        The right bound of the interval.
    • Constructor Detail

      • Interval

        protected Interval​(@NotNull
                           T begin,
                           @NotNull
                           T end)
        Constructs an interval.
        Parameters:
        begin - the left bound.
        end - the right bound.
    • Method Detail

      • of

        @NotNull
        public static <T extends Comparable<T>> Interval<T> of​(@NotNull
                                                               T begin,
                                                               @NotNull
                                                               T end)
        Returns an interval of the given values.
        Parameters:
        begin - the begin/left border (inlcusive).
        end - the end/right border (inlcusive).
        Returns:
        interval.
      • of

        @NotNull
        public static <T extends Comparable<T>> Interval<T> of​(@NotNull
                                                               T beginAndEnd)
        Returns an interval of the one given value.
        Parameters:
        beginAndEnd - both borders.
        Returns:
        interval.
      • contains

        public final boolean contains​(@NotNull
                                      T x)
        Checks whether the given value is in the interval (both interval bounds are inclusive).
        Parameters:
        x - value to check.
        Returns:
        true if the given value is in the interval.
      • getBegin

        @NotNull
        public final T getBegin()
        Getter for begin to allow using it in JSP.
        Returns:
        the left bound of the interval.
        See Also:
        begin
      • getEnd

        @NotNull
        public final T getEnd()
        Getter for end to allow using it in JSP.
        Returns:
        the right bound of the interval.
        See Also:
        end
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object