Class Assertions


  • public final class Assertions
    extends java.lang.Object
    Assertions to validate inputs
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void ensureArgument​(java.util.function.Supplier<java.lang.Boolean> argumentCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)
      Ensures the validity of arguments
      static void ensureState​(java.util.function.Supplier<java.lang.Boolean> stateCheck, java.util.function.Supplier<java.lang.String> errorMessageSupplier)
      Ensures the validity of state
      static <T> T validateConfig​(java.util.function.Supplier<T> valueSupplier, java.util.function.Supplier<java.lang.String> errorMessageSupplier)
      Checks the validity of a value
      static <T> T validateConfig​(T value, java.util.function.Predicate<T> predicate, java.util.function.Supplier<java.lang.String> errorMessageSupplier)
      Checks the validity of a value
      • Methods inherited from class java.lang.Object

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

      • ensureState

        public static void ensureState​(java.util.function.Supplier<java.lang.Boolean> stateCheck,
                                       java.util.function.Supplier<java.lang.String> errorMessageSupplier)
        Ensures the validity of state
        Parameters:
        stateCheck - the supplier of the state check
        errorMessageSupplier - the supplier of the error message if the predicate
        Throws:
        java.lang.IllegalStateException - if the state check fails
      • ensureArgument

        public static void ensureArgument​(java.util.function.Supplier<java.lang.Boolean> argumentCheck,
                                          java.util.function.Supplier<java.lang.String> errorMessageSupplier)
        Ensures the validity of arguments
        Parameters:
        argumentCheck - the supplier of the argument check
        errorMessageSupplier - the supplier of the error message if the predicate fails
        Throws:
        java.lang.IllegalArgumentException - if the argument check fails
      • validateConfig

        public static <T> T validateConfig​(T value,
                                           java.util.function.Predicate<T> predicate,
                                           java.util.function.Supplier<java.lang.String> errorMessageSupplier)
        Checks the validity of a value
        Type Parameters:
        T - the type of the value being checked
        Parameters:
        value - the value to check
        predicate - the predicate
        errorMessageSupplier - the supplier of the error message if the predicate fails
        Returns:
        the value or throw an ConfigException if the value is invalid
        Throws:
        ConfigException - if the predicate returns false
      • validateConfig

        public static <T> T validateConfig​(java.util.function.Supplier<T> valueSupplier,
                                           java.util.function.Supplier<java.lang.String> errorMessageSupplier)
        Checks the validity of a value
        Type Parameters:
        T - the type of the value being checked
        Parameters:
        valueSupplier - the supplier of the value
        errorMessageSupplier - the supplier of the error message if the predicate fails
        Returns:
        the value or throw an ConfigException if the supplier throws an exception
        Throws:
        ConfigException - if the supplier throws an exception