public final class Preconditions extends Object
Internal API: these methods are part of the internal API and may be removed, have their signature change, or have their access level decreased from public to protected, package, or private in future versions without notice.
| Modifier and Type | Method and Description |
|---|---|
static <T> Iterable<T> |
doesNotContainNull(Iterable<T> values,
String name)
Check that given iterable does not contain any
null values. |
static String |
notBlank(String value,
String name)
Check that a given string value is not blank (i.e not null, not empty and not blank).
|
static <T> Collection<T> |
notEmpty(Collection<T> collection,
String name)
Check that given collection is not empty (i.e null or with a size equal to zero).
|
static <T> T |
notNull(T value,
String name)
Check that a given value is not null.
|
static int |
positive(int value,
String name)
Check that a given integer is positive.
|
static long |
positive(long value,
String name)
Check that a given long value is positive.
|
public static <T> T notNull(T value,
String name)
NullPointerException exception if value is null or returned the
value.T - Type of value.value - Value to check.name - Name of parameter, it will produce an error message such as "{name} must not be null"NullPointerException - If value is null.public static <T> Iterable<T> doesNotContainNull(Iterable<T> values, String name)
null values.
It throws a NullPointerException exception if at least one value is null or returned the
original iterable.T - Type of value.values - Values to check.name - Name of parameter, it will produce an error message such as "{name[i]} must not be null"NullPointerException - If value is null.public static <T> Collection<T> notEmpty(Collection<T> collection, String name)
IllegalArgumentException exception if collection is empty or
returned original collection otherwise.
Generated message will be : {name} must not be empty
Where name is the value given in parameter.T - Type of elements.collection - Collection.name - Name of field to produce exception message.NullPointerException - If collection is null.IllegalArgumentException - If collection is empty.public static String notBlank(String value, String name)
NullPointerException exception if value is null and throw an
IllegalArgumentException if value is empty or blank.
Otherwise original value is returnedvalue - Value to check.name - Name of parameter, it will produce an error message such as "{name} must not be null"
or "{name} must not be blank".public static int positive(int value,
String name)
IllegalArgumentException exception,
otherwise integer value is returned.value - Value to check.name - Name of value.public static long positive(long value,
String name)
IllegalArgumentException exception,
otherwise integer value is returned.value - Value to check.name - Name of value.Copyright © 2019. All rights reserved.