Interface IntRange


  • @Immutable
    @ParametersAreNonnullByDefault
    public interface IntRange
    A range (or "interval") defines the boundaries around a contiguous span of values of integer.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      static IntRange all()
      Creates a range that contains every value of type C.
      static IntRange and​(IntRange r1, IntRange r2)
      Creates a range that contains all values enclosed by both ranges.
      static IntRange atLeast​(int lower)
      Creates a range that contains all values greater than or equal to lower.
      static IntRange atMost​(int upper)
      Creates a range that contains all values less than or equal to upper.
      static IntRange closed​(int lower, int upper)
      Creates a range that contains all values greater than or equal to lower and less than or equal to upper.
      static IntRange closedOpen​(int lower, int upper)
      Creates a range that contains all values greater than or equal to lower and strictly less than upper.
      boolean contains​(int value)
      Returns true if value is within the bounds of this range.
      default boolean containsAll​(Iterable<Integer> values)
      Returns true if every element in values is contained in this range.
      static IntRange empty()
      Creates a range that does not contain any value.
      static IntRange greaterThan​(int lower)
      Creates a range that contains all values strictly greater than lower.
      static IntRange lessThan​(int upper)
      Creates a range that contains all values strictly less than upper.
      static IntRange open​(int lower, int upper)
      Creates a range that contains all values strictly greater than lower and strictly less than upper.
      static IntRange openClosed​(int lower, int upper)
      Creates a range that contains all values strictly greater than lower and less than or equal to upper.
      static IntRange or​(IntRange r1, IntRange r2)
      Creates a range that contains all values enclosed by at least one range.
      static IntRange singleton​(int value)
      Creates a range that contains only the given value.
      static IntRange xor​(IntRange r1, IntRange r2)
      Creates a range that contains all values enclosed by one range, but not another.
    • Method Detail

      • open

        @Nonnull
        static IntRange open​(int lower,
                             int upper)
        Creates a range that contains all values strictly greater than lower and strictly less than upper.
        Parameters:
        lower - the lower bound of the range (exclusive)
        upper - the upper bound of the range (exclusive)
        Returns:
        a new range
        Throws:
        IllegalArgumentException - if lower is greater than upper
      • closed

        @Nonnull
        static IntRange closed​(int lower,
                               int upper)
        Creates a range that contains all values greater than or equal to lower and less than or equal to upper.
        Parameters:
        lower - the lower bound of the range (inclusive)
        upper - the upper bound of the range (inclusive)
        Returns:
        a new range
        Throws:
        IllegalArgumentException - if lower is greater than upper
      • openClosed

        @Nonnull
        static IntRange openClosed​(int lower,
                                   int upper)
        Creates a range that contains all values strictly greater than lower and less than or equal to upper.
        Parameters:
        lower - the lower bound of the range (exclusive)
        upper - the upper bound of the range (inclusive)
        Returns:
        a new range
        Throws:
        IllegalArgumentException - if lower is greater than upper
      • closedOpen

        @Nonnull
        static IntRange closedOpen​(int lower,
                                   int upper)
        Creates a range that contains all values greater than or equal to lower and strictly less than upper.
        Parameters:
        lower - the lower bound of the range (inclusive)
        upper - the upper bound of the range (exclusive)
        Returns:
        a new instance of range
        Throws:
        IllegalArgumentException - if lower is greater than upper
      • singleton

        @Nonnull
        static IntRange singleton​(int value)
        Creates a range that contains only the given value. The returned range is closed on both ends.
        Parameters:
        value - the unique value of the range
        Returns:
        a new range
        See Also:
        closed(int, int)
      • atLeast

        @Nonnull
        static IntRange atLeast​(int lower)
        Creates a range that contains all values greater than or equal to lower.
        Parameters:
        lower - the lower bound of the range (inclusive)
        Returns:
        a new range
      • atMost

        @Nonnull
        static IntRange atMost​(int upper)
        Creates a range that contains all values less than or equal to upper.
        Parameters:
        upper - the upper bound of the range (inclusive)
        Returns:
        a new range
      • greaterThan

        @Nonnull
        static IntRange greaterThan​(int lower)
        Creates a range that contains all values strictly greater than lower.
        Parameters:
        lower - the lower bound of the range (exclusive)
        Returns:
        a new range
      • lessThan

        @Nonnull
        static IntRange lessThan​(int upper)
        Creates a range that contains all values strictly less than upper.
        Parameters:
        upper - the upper bound of the range (exclusive)
        Returns:
        a new range
      • all

        @Nonnull
        static IntRange all()
        Creates a range that contains every value of type C.
        Returns:
        a new range
      • empty

        @Nonnull
        static IntRange empty()
        Creates a range that does not contain any value.
        Returns:
        a new range
      • contains

        boolean contains​(int value)
        Returns true if value is within the bounds of this range.
        Parameters:
        value - the value to be tested for inclusion
        Returns:
        true if value is within the bounds of this range
      • containsAll

        default boolean containsAll​(Iterable<Integer> values)
        Returns true if every element in values is contained in this range.
        Parameters:
        values - the value to be tested for inclusion
        Returns:
        true if every element in values is contained in this range
        Throws:
        NullPointerException - if any argument is null
        See Also:
        contains(int)