Enum Ensures

  • All Implemented Interfaces:
    Serializable, Comparable<Ensures>

    public enum Ensures
    extends Enum<Ensures>
    Static convenience methods that help a method or constructor check whether it was invoked correctly.

    Other types of preconditions

    Not every type of precondition failure is supported by these methods. Continue to throw standard JDK exceptions such as NoSuchElementException or UnsupportedOperationException in the situations they are intended for.

    href="https://github.com/google/guava/wiki/ConditionalFailuresExplained">Conditional failures explained

    java.util.Objects.requireNonNull()

    Projects which use com.google.common should generally avoid the use of Objects.requireNonNull(Object). Instead, use whichever of checkNotNull(Object) or Verify#verifyNotNull(Object) is appropriate to the situation. (The same goes for the message-accepting overloads.)

    • Method Detail

      • values

        public static Ensures[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (Ensures c : Ensures.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static Ensures valueOf​(String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • checkArgument

        public static void checkArgument​(boolean expression)
      • checkArgument

        public static void checkArgument​(boolean expression,
                                         Supplier<Object> errorMessage)
      • checkState

        public static void checkState​(boolean expression)
      • checkState

        public static void checkState​(boolean expression,
                                      Supplier<Object> errorMessage)
      • checkNotNull

        public static <T> T checkNotNull​(T reference)
      • checkNotNull

        public static <T> T checkNotNull​(T reference,
                                         Supplier<Object> errorMessage)
      • notEmpty

        public static <T> T[] notEmpty​(T[] array)
        Assert that the supplied array is neither null nor empty.

        WARNING: this method does NOT check if the supplied array contains any null elements.

        Parameters:
        array - the array to check
        Returns:
        the supplied array as a convenience
        Throws:
        IllegalStateException - if the supplied array is null or empty
        See Also:
        condition(boolean)
      • notEmpty

        public static <T> T[] notEmpty​(T[] array,
                                       Supplier<Object> errorMessage)
        Assert that the supplied array is neither null nor empty.

        WARNING: this method does NOT check if the supplied array contains any null elements.

        Parameters:
        array - the array to check
        errorMessage - precondition violation message supplier
        Returns:
        the supplied array as a convenience
        Throws:
        IllegalStateException - if the supplied array is null or empty
        See Also:
        condition(boolean, Supplier)
      • notEmpty

        public static <T extends Collection<?>> T notEmpty​(T collection)
        Assert that the supplied Collection is neither null nor empty.

        WARNING: this method does NOT check if the supplied collection contains any null elements.

        Parameters:
        collection - the collection to check
        Returns:
        the supplied collection as a convenience
        Throws:
        IllegalStateException - if the supplied collection is null or empty
        See Also:
        condition(boolean)
      • notEmpty

        public static <T extends Collection<?>> T notEmpty​(T collection,
                                                           Supplier<Object> errorMessage)
        Assert that the supplied Collection is neither null nor empty.

        WARNING: this method does NOT check if the supplied collection contains any null elements.

        Parameters:
        collection - the collection to check
        errorMessage - precondition violation message supplier
        Returns:
        the supplied collection as a convenience
        Throws:
        IllegalStateException - if the supplied collection is null or empty
        See Also:
        condition(boolean, Supplier)
      • notBlank

        public static String notBlank​(String str)
        Assert that the supplied String is not blank.

        A String is blank if it is null or consists only of whitespace characters.

        Parameters:
        str - the string to check
        Returns:
        the supplied string as a convenience
        Throws:
        IllegalStateException - if the supplied string is blank
        See Also:
        notBlank(String, Supplier)
      • condition

        public static void condition​(boolean predicate)
        Assert that the supplied predicate is true.
        Parameters:
        predicate - the predicate to check
        Throws:
        IllegalStateException - if the predicate is false
        See Also:
        condition(boolean, Supplier)
      • condition

        public static void condition​(boolean predicate,
                                     Supplier<Object> errorMessage)
        Assert that the supplied predicate is true.
        Parameters:
        predicate - the predicate to check
        errorMessage - precondition violation message supplier
        Throws:
        IllegalStateException - if the predicate is false