Class Require


  • public final class Require
    extends java.lang.Object
    A utility class to check arguments (preconditions) and state.

    Examples of use:

       public void setActionWithTimeout(Action action delegate, int timeout) {
         this.action = Require.nonNull("Action", action);
         this.timeout = Require.positive("Timeout", timeout);
       }
     
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Require.FileChecker argument​(java.lang.String argName, java.io.File file)  
      static Require.IntChecker argument​(java.lang.String argName, java.lang.Integer number)  
      static <T> Require.ArgumentChecker<T> argument​(java.lang.String argName, T arg)  
      static int nonNegative​(java.lang.String argName, java.lang.Integer number)  
      static java.time.Duration nonNegative​(java.lang.String argName, java.time.Duration arg)  
      static java.time.Duration nonNegative​(java.time.Duration arg)  
      static <T> T nonNull​(java.lang.String argName, T arg)  
      static <T> T nonNull​(java.lang.String argName, T arg, java.lang.String message, java.lang.Object... args)  
      static double positive​(java.lang.String argName, java.lang.Double number)  
      static double positive​(java.lang.String argName, java.lang.Double number, java.lang.String message)  
      static int positive​(java.lang.String argName, java.lang.Integer number)  
      static int positive​(java.lang.String argName, java.lang.Integer number, java.lang.String message)  
      static java.time.Duration positive​(java.lang.String argName, java.time.Duration arg)  
      static java.time.Duration positive​(java.time.Duration arg)  
      static void precondition​(boolean condition, java.lang.String message, java.lang.Object... args)  
      static Require.FileStateChecker state​(java.lang.String name, java.io.File file)  
      static Require.PathStateChecker state​(java.lang.String name, java.nio.file.Path path)  
      static <T> Require.StateChecker<T> state​(java.lang.String name, T state)  
      static void stateCondition​(boolean state, java.lang.String message, java.lang.Object... args)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • precondition

        public static void precondition​(boolean condition,
                                        java.lang.String message,
                                        java.lang.Object... args)
      • nonNull

        public static <T> T nonNull​(java.lang.String argName,
                                    T arg)
      • nonNull

        public static <T> T nonNull​(java.lang.String argName,
                                    T arg,
                                    java.lang.String message,
                                    java.lang.Object... args)
      • nonNegative

        public static java.time.Duration nonNegative​(java.lang.String argName,
                                                     java.time.Duration arg)
      • nonNegative

        public static java.time.Duration nonNegative​(java.time.Duration arg)
      • positive

        public static java.time.Duration positive​(java.lang.String argName,
                                                  java.time.Duration arg)
      • positive

        public static java.time.Duration positive​(java.time.Duration arg)
      • nonNegative

        public static int nonNegative​(java.lang.String argName,
                                      java.lang.Integer number)
      • positive

        public static int positive​(java.lang.String argName,
                                   java.lang.Integer number,
                                   java.lang.String message)
      • positive

        public static double positive​(java.lang.String argName,
                                      java.lang.Double number,
                                      java.lang.String message)
      • positive

        public static double positive​(java.lang.String argName,
                                      java.lang.Double number)
      • positive

        public static int positive​(java.lang.String argName,
                                   java.lang.Integer number)
      • argument

        public static Require.IntChecker argument​(java.lang.String argName,
                                                  java.lang.Integer number)
      • argument

        public static Require.FileChecker argument​(java.lang.String argName,
                                                   java.io.File file)
      • stateCondition

        public static void stateCondition​(boolean state,
                                          java.lang.String message,
                                          java.lang.Object... args)