public enum Ensures extends Enum<Ensures>
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.)
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
checkArgument(boolean expression) |
static void |
checkArgument(boolean expression,
Supplier<Object> errorMessage) |
static <T> T |
checkNotNull(T reference) |
static <T> T |
checkNotNull(T reference,
Supplier<Object> errorMessage) |
static void |
checkState(boolean expression) |
static void |
checkState(boolean expression,
Supplier<Object> errorMessage) |
static void |
condition(boolean predicate)
Assert that the supplied
predicate is true. |
static void |
condition(boolean predicate,
Supplier<Object> errorMessage)
Assert that the supplied
predicate is true. |
static String |
notBlank(String str)
Assert that the supplied
String is not blank. |
static String |
notBlank(String str,
Supplier<Object> errorMessage)
Assert that the supplied
String is not blank. |
static <T extends Collection<?>> |
notEmpty(T collection)
Assert that the supplied
Collection is neither null nor empty. |
static <T> T[] |
notEmpty(T[] array)
Assert that the supplied array is neither
null nor empty. |
static <T> T[] |
notEmpty(T[] array,
Supplier<Object> errorMessage)
Assert that the supplied array is neither
null nor empty. |
static <T extends Collection<?>> |
notEmpty(T collection,
Supplier<Object> errorMessage)
Assert that the supplied
Collection is neither null nor empty. |
static Ensures |
valueOf(String name)
返回带有指定名称的该类型的枚举常量。
|
static Ensures[] |
values()
按照声明该枚举类型的常量的顺序, 返回
包含这些常量的数组。
|
public static Ensures[] values()
for (Ensures c : Ensures.values()) System.out.println(c);
public static Ensures valueOf(String name)
name - 要返回的枚举常量的名称。IllegalArgumentException - 如果该枚举类型没有带有指定名称的常量NullPointerException - 如果参数为空值public static void checkArgument(boolean expression)
public static void checkState(boolean expression)
public static <T> T checkNotNull(T reference)
public static <T> T[] notEmpty(T[] array)
null nor empty.
WARNING: this method does NOT check if the supplied
array contains any null elements.
array - the array to checkIllegalStateException - if the supplied array is
null or emptycondition(boolean)public static <T> T[] notEmpty(T[] array,
Supplier<Object> errorMessage)
null nor empty.
WARNING: this method does NOT check if the supplied
array contains any null elements.
array - the array to checkerrorMessage - precondition violation message supplierIllegalStateException - if the supplied array is
null or emptycondition(boolean, Supplier)public static <T extends Collection<?>> T notEmpty(T collection)
Collection is neither null nor empty.
WARNING: this method does NOT check if the supplied
collection contains any null elements.
collection - the collection to checkIllegalStateException - if the supplied collection is null or emptycondition(boolean)public static <T extends Collection<?>> T notEmpty(T collection, Supplier<Object> errorMessage)
Collection is neither null nor empty.
WARNING: this method does NOT check if the supplied
collection contains any null elements.
collection - the collection to checkerrorMessage - precondition violation message supplierIllegalStateException - if the supplied collection is null or emptycondition(boolean, Supplier)public static String notBlank(String str)
String is not blank.
A String is blank if it is null or consists
only of whitespace characters.
str - the string to checkIllegalStateException - if the supplied string is blanknotBlank(String, Supplier)public static String notBlank(String str, Supplier<Object> errorMessage)
String is not blank.
A String is blank if it is null or consists
only of whitespace characters.
str - the string to checkerrorMessage - precondition violation message supplierIllegalStateException - if the supplied string is blankStringUtils.isNotBlank(String),
condition(boolean, Supplier)public static void condition(boolean predicate)
predicate is true.predicate - the predicate to checkIllegalStateException - if the predicate is falsecondition(boolean, Supplier)public static void condition(boolean predicate,
Supplier<Object> errorMessage)
predicate is true.predicate - the predicate to checkerrorMessage - precondition violation message supplierIllegalStateException - if the predicate is falseCopyright © 2021. All rights reserved.