Class LongRangeUtil


  • public final class LongRangeUtil
    extends Object
    Utility class for checking invariants on long-values.
    Author:
    Emil Forslund
    • Method Detail

      • requirePositive

        public static long requirePositive​(long val)
        Returns the given value if it is positive.
        Parameters:
        val - to check
        Returns:
        the given value
        Throws:
        IllegalArgumentException - if the given value is not positive
      • requireNegative

        public static long requireNegative​(long val)
      • requireZero

        public static long requireZero​(long val)
      • requireNonPositive

        public static long requireNonPositive​(long val)
      • requireNonNegative

        public static long requireNonNegative​(long val)
      • requireNonZero

        public static long requireNonZero​(long val)
      • requireEquals

        public static long requireEquals​(long val,
                                         long otherVal)
      • requireNotEquals

        public static long requireNotEquals​(long val,
                                            long otherVal)
      • requireInRange

        public static long requireInRange​(long val,
                                          long first,
                                          long lastExclusive)
      • requireInRangeClosed

        public static long requireInRangeClosed​(long val,
                                                long first,
                                                long lastInclusive)
      • requirePositive

        public static <E extends RuntimeException> long requirePositive​(long val,
                                                                        Function<String,​E> exceptionConstructor)
        Returns the given value if it is positive.
        Type Parameters:
        E - RuntimeException type
        Parameters:
        val - to check
        exceptionConstructor - to use when throwing exception
        Returns:
        the given value
        Throws:
        RuntimeException - if the given value is not positive
      • requireEquals

        public static <E extends RuntimeException> long requireEquals​(long val,
                                                                      long otherVal,
                                                                      Function<String,​E> exceptionConstructor)
      • requireNotEquals

        public static <E extends RuntimeException> long requireNotEquals​(long val,
                                                                         long otherVal,
                                                                         Function<String,​E> exceptionConstructor)
      • requireInRange

        public static <E extends RuntimeException> long requireInRange​(long val,
                                                                       long first,
                                                                       long lastExclusive,
                                                                       Function<String,​E> exceptionConstructor)
      • requireInRangeClosed

        public static <E extends RuntimeException> long requireInRangeClosed​(long val,
                                                                             long first,
                                                                             long lastInclusive,
                                                                             Function<String,​E> exceptionConstructor)