Enum Ensures
- java.lang.Object
-
- java.lang.Enum<Ensures>
-
- cn.sliew.milky.common.check.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
NoSuchElementExceptionorUnsupportedOperationExceptionin 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.commonshould generally avoid the use ofObjects.requireNonNull(Object). Instead, use whichever ofcheckNotNull(Object)orVerify#verifyNotNull(Object)is appropriate to the situation. (The same goes for the message-accepting overloads.)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckArgument(boolean expression)static voidcheckArgument(boolean expression, Supplier<Object> errorMessage)static <T> TcheckNotNull(T reference)static <T> TcheckNotNull(T reference, Supplier<Object> errorMessage)static voidcheckState(boolean expression)static voidcheckState(boolean expression, Supplier<Object> errorMessage)static voidcondition(boolean predicate)Assert that the suppliedpredicateistrue.static voidcondition(boolean predicate, Supplier<Object> errorMessage)Assert that the suppliedpredicateistrue.static StringnotBlank(String str)Assert that the suppliedStringis not blank.static StringnotBlank(String str, Supplier<Object> errorMessage)Assert that the suppliedStringis not blank.static <T extends Collection<?>>
TnotEmpty(T collection)Assert that the suppliedCollectionis neithernullnor empty.static <T> T[]notEmpty(T[] array)Assert that the supplied array is neithernullnor empty.static <T> T[]notEmpty(T[] array, Supplier<Object> errorMessage)Assert that the supplied array is neithernullnor empty.static <T extends Collection<?>>
TnotEmpty(T collection, Supplier<Object> errorMessage)Assert that the suppliedCollectionis neithernullnor empty.static EnsuresvalueOf(String name)Returns the enum constant of this type with the specified name.static Ensures[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
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 nameNullPointerException- if the argument is null
-
checkArgument
public static void checkArgument(boolean expression)
-
checkState
public static void checkState(boolean expression)
-
checkNotNull
public static <T> T checkNotNull(T reference)
-
notEmpty
public static <T> T[] notEmpty(T[] array)
Assert that the supplied array is neithernullnor empty.WARNING: this method does NOT check if the supplied array contains any
nullelements.- Parameters:
array- the array to check- Returns:
- the supplied array as a convenience
- Throws:
IllegalStateException- if the supplied array isnullor empty- See Also:
condition(boolean)
-
notEmpty
public static <T> T[] notEmpty(T[] array, Supplier<Object> errorMessage)Assert that the supplied array is neithernullnor empty.WARNING: this method does NOT check if the supplied array contains any
nullelements.- Parameters:
array- the array to checkerrorMessage- precondition violation message supplier- Returns:
- the supplied array as a convenience
- Throws:
IllegalStateException- if the supplied array isnullor empty- See Also:
condition(boolean, Supplier)
-
notEmpty
public static <T extends Collection<?>> T notEmpty(T collection)
Assert that the suppliedCollectionis neithernullnor empty.WARNING: this method does NOT check if the supplied collection contains any
nullelements.- Parameters:
collection- the collection to check- Returns:
- the supplied collection as a convenience
- Throws:
IllegalStateException- if the supplied collection isnullor empty- See Also:
condition(boolean)
-
notEmpty
public static <T extends Collection<?>> T notEmpty(T collection, Supplier<Object> errorMessage)
Assert that the suppliedCollectionis neithernullnor empty.WARNING: this method does NOT check if the supplied collection contains any
nullelements.- Parameters:
collection- the collection to checkerrorMessage- precondition violation message supplier- Returns:
- the supplied collection as a convenience
- Throws:
IllegalStateException- if the supplied collection isnullor empty- See Also:
condition(boolean, Supplier)
-
notBlank
public static String notBlank(String str)
Assert that the suppliedStringis not blank.A
Stringis blank if it isnullor 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)
-
notBlank
public static String notBlank(String str, Supplier<Object> errorMessage)
Assert that the suppliedStringis not blank.A
Stringis blank if it isnullor consists only of whitespace characters.- Parameters:
str- the string to checkerrorMessage- precondition violation message supplier- Returns:
- the supplied string as a convenience
- Throws:
IllegalStateException- if the supplied string is blank- See Also:
StringUtils.isNotBlank(String),condition(boolean, Supplier)
-
condition
public static void condition(boolean predicate)
Assert that the suppliedpredicateistrue.- Parameters:
predicate- the predicate to check- Throws:
IllegalStateException- if the predicate isfalse- See Also:
condition(boolean, Supplier)
-
condition
public static void condition(boolean predicate, Supplier<Object> errorMessage)Assert that the suppliedpredicateistrue.- Parameters:
predicate- the predicate to checkerrorMessage- precondition violation message supplier- Throws:
IllegalStateException- if the predicate isfalse
-
-