Class Preconditions


  • public class Preconditions
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      Preconditions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <X extends java.lang.Throwable>
      void
      check​(boolean expression, java.util.function.Supplier<? extends X> exceptionSupplier)
      Ensures the truth of an expression, throwing a custom exception if untrue.
      static void checkArgument​(boolean expression)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      static void checkArgument​(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
      Ensures the truth of an expression involving one or more parameters to the calling method.
      static void checkState​(boolean expression)
      Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
      static void checkState​(boolean expression, java.util.function.Supplier<java.lang.String> messageSupplier)
      Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
      • Methods inherited from class java.lang.Object

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

      • Preconditions

        public Preconditions()
    • Method Detail

      • checkArgument

        public static void checkArgument​(boolean expression)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        expression - a boolean expression
        Throws:
        java.lang.IllegalArgumentException - if expression is false
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         java.util.function.Supplier<java.lang.String> messageSupplier)
        Ensures the truth of an expression involving one or more parameters to the calling method.
        Parameters:
        expression - a boolean expression
        messageSupplier - supplier of the detail message to be used in the event that a IllegalArgumentException is thrown
        Throws:
        java.lang.IllegalArgumentException - if expression is false
      • checkState

        public static void checkState​(boolean expression)
        Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
        Parameters:
        expression - a boolean expression
        Throws:
        java.lang.IllegalStateException - if expression is false
      • checkState

        public static void checkState​(boolean expression,
                                      java.util.function.Supplier<java.lang.String> messageSupplier)
        Ensures the truth of an expression involving the state of the calling instance, but not involving any parameters to the calling method.
        Parameters:
        expression - a boolean expression
        messageSupplier - supplier of the detail message to be used in the event that a IllegalStateException is thrown
        Throws:
        java.lang.IllegalStateException - if expression is false
      • check

        public static <X extends java.lang.Throwable> void check​(boolean expression,
                                                                 java.util.function.Supplier<? extends X> exceptionSupplier)
                                                          throws X extends java.lang.Throwable
        Ensures the truth of an expression, throwing a custom exception if untrue.
        Parameters:
        expression - a boolean expression
        exceptionSupplier - supplier of the exception to be thrown
        Throws:
        X - if expression is false
        X extends java.lang.Throwable