Interface IntegerRange


  • public interface IntegerRange
    Range of integers.
    • Method Detail

      • of

        @NonNull
        static IntegerRange of​(int lower,
                               int upper)
        Creates an immutable IntegerRange.
        Parameters:
        lower - range lower bound
        upper - range upper bound
        Returns:
        a new immutable IntegerRange instance
      • getLower

        int getLower()
        Gets lower bound.
        Returns:
        the lower bound
      • getUpper

        int getUpper()
        Gets upper bound.
        Returns:
        the upper bound
      • contains

        default boolean contains​(int value)
        Tells whether this range may contain some value.
        Parameters:
        value - value to test
        Returns:
        true if the provided value fits within this range, otherwise false
      • clamp

        default int clamp​(int value)
        Clamps a value to this range.
        • In case value is less than lower bound, returns lower bound,
        • otherwise if value is greater than upper bound, returns upper bound,
        • otherwise, returns value.
        Parameters:
        value - value to clamp
        Returns:
        a value clamped to this range
      • scaleFrom

        default int scaleFrom​(int value,
                              @NonNull
                              IntegerRange src)
        Scales a value from a given range to this range.

        The given range should respect the following condition: src.getLower() < src.getUpper()

        Parameters:
        value - value to scale
        src - range to scale from
        Returns:
        a value linearly scaled to this range from value in src