Class RequireUtil

java.lang.Object
org.opencastproject.util.RequireUtil

public final class RequireUtil extends Object
Utility functions for handling common requirements.
  • Method Details

    • requireTrue

      public static void requireTrue(boolean expr, String exprName)
      Require an expression to hold true.
      Parameters:
      expr - the expression
      exprName - the name of the expression used to create an error message in case expr evaluates to false
      Throws:
      IllegalArgumentException - in case expr evaluates to false
    • notNull

      public static <A> A notNull(A value, String valueName)
      The given value must not be null.

      Example:

       class A {
         private String a;
      
         A(String a) {
           this.a = notNull(a, "a");
         }
       }
       
      Parameters:
      value - the value to check for null
      valueName - the name of the value; used in error message
      Returns:
      the value, if it is not null
      Throws:
      IllegalArgumentException - in case of value being null
    • notEmpty

      public static String notEmpty(String value, String valueName)
      The given value must not be null or empty.

      Example:

       class A {
         private String a;
      
         A(String a) {
           this.a = notEmpty(a, "a");
         }
       }
       
      Parameters:
      value - the value to check for emptiness
      valueName - the name of the value; used in error message
      Returns:
      the value, if it is not empty
      Throws:
      IllegalArgumentException - in case of value being empty
    • requireNotBlank

      public static String requireNotBlank(String value, String valueName)
      The given string value must not be blank, empty nor null. Otherwise, an IllegalArgumentException is thrown.
      Parameters:
      value - the value to check for not being empty
      valueName - the name of the value
      Returns:
      the value, if not blank
    • between

      public static double between(double value, double min, double max)
    • min

      public static int min(int value, int min)