Class FailFast

    • Constructor Detail

      • FailFast

        public FailFast()
    • Method Detail

      • requireMustBeInstanceOf

        public static <T> T requireMustBeInstanceOf​(Object objectThatMustBeAnInstanceOf,
                                                    Class<T> mustBeAnInstanceOf)
        Assert that the objectThatMustBeAnInstanceOf is an instance of mustBeAnInstanceOf parameter, if not then IllegalArgumentException is thrown
        Type Parameters:
        T - the type of class that the objectThatMustBeAnInstanceOf must be an instance of
        Parameters:
        objectThatMustBeAnInstanceOf - the object that must be an instance of mustBeAnInstanceOf parameter
        mustBeAnInstanceOf - the type that the objectThatMustBeAnInstanceOf parameter must be an instance of
        Returns:
        the "objectThatMustBeAnInstanceOf" IF it is of the right type
      • requireMustBeInstanceOf

        public static <T> T requireMustBeInstanceOf​(Object objectThatMustBeAnInstanceOf,
                                                    Class<?> mustBeAnInstanceOf,
                                                    String message)
        Assert that the objectThatMustBeAnInstanceOf is an instance of mustBeAnInstanceOf parameter, if not then IllegalArgumentException is thrown
        Type Parameters:
        T - the type of class that the objectThatMustBeAnInstanceOf must be an instance of
        Parameters:
        objectThatMustBeAnInstanceOf - the object that must be an instance of mustBeAnInstanceOf parameter
        mustBeAnInstanceOf - the type that the objectThatMustBeAnInstanceOf parameter must be an instance of
        message - the optional message that will become the message of the IllegalArgumentException in case the objectThatMustBeAnInstanceOf is NOT an instance of mustBeAnInstanceOf
        Returns:
        the "objectThatMustBeAnInstanceOf" IF it is of the right type
      • requireNonNull

        public static <T> T requireNonNull​(T objectThatMayNotBeNull,
                                           String message)
        Assert that the objectThatMayNotBeNull is NOT null. If it's null then an IllegalArgumentException is thrown
        Type Parameters:
        T - the type of the objectThatMayNotBeNull
        Parameters:
        objectThatMayNotBeNull - the object that must NOT be null
        message - the optional message that will become the message of the IllegalArgumentException in case the objectThatMayNotBeNull is NULL
        Returns:
        the "objectThatMayNotBeNull" IF it's not null
      • requireNonBlank

        public static <T extends CharSequence> T requireNonBlank​(T characterStreamThatMustNotBeEmptyOrNull,
                                                                 String message)
        Assert that the characterStreamThatMustNotBeEmptyOrNull is NOT null AND NOT empty/blank, otherwise a IllegalArgumentException is thrown
        Type Parameters:
        T - the type of the characterStreamThatMustNotBeEmptyOrNull
        Parameters:
        characterStreamThatMustNotBeEmptyOrNull - the object that must NOT be null or empty
        message - the optional message that will become the message of the IllegalArgumentException in case the characterStreamThatMustNotBeEmptyOrNull is NULL
        Returns:
        the "characterStreamThatMustNotBeEmptyOrNull" IF it's not null
      • requireNonNull

        public static <T> T requireNonNull​(T objectThatMayNotBeNull,
                                           String message,
                                           Object... messageArguments)
        Assert that the objectThatMayNotBeNull is NOT null. If it's null then an IllegalArgumentException is thrown
        Short handle for calling requireNonNull(someObjectThatMustNotBeNull, m("Message with {} placeholder", someMessageObject)) - (see MessageFormatter.msg(String, Object...))
        Type Parameters:
        T - the type of the objectThatMayNotBeNull
        Parameters:
        objectThatMayNotBeNull - the object that must NOT be null
        message - the optional message that will become the message of the IllegalArgumentException in case the objectThatMayNotBeNull is NULL
        messageArguments - any placeholders for the message (see MessageFormatter.msg(String, Object...))
        Returns:
        the "objectThatMayNotBeNull" IF it's not null
      • requireNonNull

        public static <T> T requireNonNull​(T objectThatMayNotBeNull)
        Assert that the objectThatMayNotBeNull is NOT null. If it's null then an IllegalArgumentException is thrown
        Type Parameters:
        T - the type of the objectThatMayNotBeNull
        Parameters:
        objectThatMayNotBeNull - the object that must NOT be null
        Returns:
        the "objectThatMayNotBeNull" IF it's not null
      • requireTrue

        public static void requireTrue​(boolean mustBeTrue,
                                       String message)
        Assert that the boolean value mustBeTrue is true. If not then an IllegalArgumentException is thrown
        Parameters:
        mustBeTrue - boolean value that we will assert MUST be TRUE
        message - the NON optional message that will become the message of the IllegalArgumentException in case the mustBeTrue is FALSE
      • requireFalse

        public static void requireFalse​(boolean mustBeFalse,
                                        String message)
        Assert that the boolean value mustBeTrue is true. If not then an IllegalArgumentException is thrown
        Parameters:
        mustBeFalse - boolean value that we will assert MUST be FALSE
        message - the NON optional message that will become the message of the IllegalArgumentException in case the mustBeFalse is TRUE
      • requireNonEmpty

        public static Object[] requireNonEmpty​(Object[] items,
                                               String message)
      • requireNonEmpty

        public static <T> List<T> requireNonEmpty​(List<T> items,
                                                  String message)
      • requireNonEmpty

        public static <T> Set<T> requireNonEmpty​(Set<T> items,
                                                 String message)
      • requireNonEmpty

        public static <K,​V> Map<K,​V> requireNonEmpty​(Map<K,​V> items,
                                                                 String message)