public final class Preconditions extends Object
Modifier and Type | Method and Description |
---|---|
static int |
checkAsyncBackupCount(int currentBackupCount,
int newAsyncBackupCount)
Tests if the newAsyncBackupCount count is valid.
|
static int |
checkBackupCount(int newBackupCount,
int currentAsyncBackupCount)
Tests if the newBackupCount count is valid.
|
static void |
checkFalse(boolean expression,
String errorMessage)
Tests whether the supplied expression is
false . |
static <T> Iterator<T> |
checkHasNext(Iterator<T> iterator,
String message)
Check if iterator has next element.
|
static String |
checkHasText(String argument,
String errorMessage)
Tests if a string contains text.
|
static <E> E |
checkInstanceOf(Class<E> type,
Object object) |
static <E> E |
checkInstanceOf(Class<E> type,
Object object,
String errorMessage)
Tests whether the supplied object is an instance of the supplied class type.
|
static long |
checkNegative(long value,
String errorMessage)
Tests if the
value is < 0. |
static <T> Iterable<T> |
checkNoNullInside(Iterable<T> argument,
String errorMessage)
Tests if the elements inside the argument collection are not null.
|
static <E> E |
checkNotInstanceOf(Class type,
E object,
String errorMessage)
Tests the supplied object to see if it is not a type of the supplied class.
|
static int |
checkNotNegative(int value,
String errorMessage)
Tests if the
value is >= 0. |
static long |
checkNotNegative(long value,
String errorMessage)
Tests if the
value is >= 0. |
static <T> T |
checkNotNull(T argument)
Tests if an argument is not null.
|
static <T> T |
checkNotNull(T argument,
String errorMessage)
Tests if an argument is not null.
|
static double |
checkPositive(double value,
String errorMessage)
Tests if a
value is positive, that is strictly larger than 0 (value > 0). |
static int |
checkPositive(int value,
String errorMessage)
Tests if a
value is positive, that is strictly larger than 0 (value > 0). |
static long |
checkPositive(long value,
String errorMessage)
Tests if a
value is positive, that is strictly larger than 0 (value > 0). |
static void |
checkState(boolean condition,
String message)
Check the state of a condition
|
static void |
checkTrue(boolean expression,
String errorMessage)
Tests whether the supplied expression is
true . |
static <E> E |
isNotNull(E argument,
String argName)
Tests if a string is not null.
|
public static String checkHasText(String argument, String errorMessage)
argument
- the string tested to see if it contains text.errorMessage
- the errorMessageIllegalArgumentException
- if the string is emptypublic static <T> T checkNotNull(T argument, String errorMessage)
argument
- the argument tested to see if it is not null.errorMessage
- the errorMessageNullPointerException
- if argument is nullpublic static <T> Iterable<T> checkNoNullInside(Iterable<T> argument, String errorMessage)
argument
- the iterable tested to see if it does not contain null elements; may be null or emptyerrorMessage
- the errorMessageNullPointerException
- if argument contains a null element insidepublic static <T> T checkNotNull(T argument)
argument
- the argument tested to see if it is not null.NullPointerException
- if argument is nullpublic static <E> E isNotNull(E argument, String argName)
argument
- the string tested to see if it is not null.argName
- the string name (used in message if an error is thrown).IllegalArgumentException
- if the string is null.public static long checkNotNegative(long value, String errorMessage)
value
is >= 0.value
- the value tested to see if it is not negative.errorMessage
- the errorMessageIllegalArgumentException
- if the value is negative.public static int checkNotNegative(int value, String errorMessage)
value
is >= 0.value
- the value tested to see if it is not negative.errorMessage
- the errorMessageIllegalArgumentException
- if the value is negative.public static long checkNegative(long value, String errorMessage)
value
is < 0.value
- the long value tested to see if it is not negative.errorMessage
- the messageIllegalArgumentException
- if the value is negative.public static long checkPositive(long value, String errorMessage)
value
is positive, that is strictly larger than 0 (value > 0).value
- the value tested to see if it is positive.errorMessage
- the messageIllegalArgumentException
- if the value is not positive.public static double checkPositive(double value, String errorMessage)
value
is positive, that is strictly larger than 0 (value > 0).value
- the value tested to see if it is positive.errorMessage
- the messageIllegalArgumentException
- if the value is not positive.public static int checkPositive(int value, String errorMessage)
value
is positive, that is strictly larger than 0 (value > 0).value
- the value tested to see if it is positive.errorMessage
- the messageIllegalArgumentException
- if the value is not positive.public static int checkBackupCount(int newBackupCount, int currentAsyncBackupCount)
newBackupCount
- the number of sync backupscurrentAsyncBackupCount
- the current number of async backupsIllegalArgumentException
- if newBackupCount is smaller than 0, or larger than the maximum
number of backups.public static int checkAsyncBackupCount(int currentBackupCount, int newAsyncBackupCount)
currentBackupCount
- the current number of backupsnewAsyncBackupCount
- the new number of async backupsIllegalArgumentException
- if asyncBackupCount is smaller than 0, or larger than the maximum
number of backups.public static <E> E checkInstanceOf(Class<E> type, Object object, String errorMessage)
type
- the expected type.object
- the object tested against the expected type.errorMessage
- the errorMessageIllegalArgumentException
- if the object is not an instance of the expected type.public static <E> E checkNotInstanceOf(Class type, E object, String errorMessage)
type
- the type that is not of the supplied class.object
- the object tested against the type.errorMessage
- the errorMessageIllegalArgumentException
- if the object is an instance of the type that is not of the expected class.public static void checkFalse(boolean expression, String errorMessage)
false
.expression
- the expression tested to see if it is false
.errorMessage
- the errorMessageIllegalArgumentException
- if the supplied expression is true
.public static void checkTrue(boolean expression, String errorMessage)
true
.expression
- the expression tested to see if it is true
.errorMessage
- the errorMessageIllegalArgumentException
- if the supplied expression is false
.public static <T> Iterator<T> checkHasNext(Iterator<T> iterator, String message) throws NoSuchElementException
iterator
- message
- NoSuchElementException
- if iterator.hasNext returns falsepublic static void checkState(boolean condition, String message) throws IllegalStateException
condition
- message
- IllegalStateException
- if condition if falseCopyright © 2018 Hazelcast, Inc.. All rights reserved.