public final class Validate
extends java.lang.Object
It provides consistent message strings for frequently encountered checks. That simplifies callers because they have to supply only the name of the argument that failed a check instead of having to supply the entire message.
| Modifier and Type | Method | Description |
|---|---|---|
static void |
checkGreater(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name) |
Validates that the first value is greater than the second value.
|
static void |
checkGreaterOrEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name) |
Validates that the first value is greater than or equal to the second value.
|
static void |
checkIntegerMultiple(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name) |
Validates that the first value is an integer multiple of the second value.
|
static void |
checkLessOrEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name) |
Validates that the first value is less than or equal to the second value.
|
static void |
checkNotNegative(long value,
java.lang.String argName) |
Validates that the given integer argument is not negative.
|
static void |
checkNotNull(java.lang.Object obj,
java.lang.String argName) |
Validates that the given reference argument is not null.
|
static void |
checkNotNullAndNotEmpty(byte[] array,
java.lang.String argName) |
Validates that the given array is not null and has at least one element.
|
static void |
checkNotNullAndNotEmpty(int[] array,
java.lang.String argName) |
Validates that the given array is not null and has at least one element.
|
static void |
checkNotNullAndNotEmpty(long[] array,
java.lang.String argName) |
Validates that the given array is not null and has at least one element.
|
static void |
checkNotNullAndNotEmpty(short[] array,
java.lang.String argName) |
Validates that the given array is not null and has at least one element.
|
static <T> void |
checkNotNullAndNotEmpty(java.lang.Iterable<T> iter,
java.lang.String argName) |
Validates that the given buffer is not null and has non-zero capacity.
|
static void |
checkNotNullAndNotEmpty(java.lang.String arg,
java.lang.String argName) |
Validates that the given string is not null and has non-zero length.
|
static <T> void |
checkNotNullAndNotEmpty(T[] array,
java.lang.String argName) |
Validates that the given array is not null and has at least one element.
|
static <T> void |
checkNotNullAndNumberOfElements(java.util.Collection<T> collection,
int numElements,
java.lang.String argName) |
Validates that the given set is not null and has an exact number of items.
|
static void |
checkPathExists(java.nio.file.Path path,
java.lang.String argName) |
Validates that the given path exists.
|
static void |
checkPathExistsAsDir(java.nio.file.Path path,
java.lang.String argName) |
Validates that the given path exists and is a directory.
|
static void |
checkPathExistsAsFile(java.nio.file.Path path,
java.lang.String argName) |
Validates that the given path exists and is a file.
|
static void |
checkPositiveInteger(long value,
java.lang.String argName) |
Validates that the given integer argument is not zero or negative.
|
static void |
checkRequired(boolean isPresent,
java.lang.String argName) |
Validates that the expression (that checks a required field is present) is true.
|
static void |
checkState(boolean expression,
java.lang.String format,
java.lang.Object... args) |
Check state.
|
static void |
checkValid(boolean isValid,
java.lang.String argName) |
Validates that the expression (that checks a field is valid) is true.
|
static void |
checkValid(boolean isValid,
java.lang.String argName,
java.lang.String validValues) |
Validates that the expression (that checks a field is valid) is true.
|
static void |
checkValuesEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name) |
Validates that the given two values are equal.
|
static void |
checkWithinRange(double value,
java.lang.String valueName,
double minValueInclusive,
double maxValueInclusive) |
Validates that the given value is within the given range of values.
|
static void |
checkWithinRange(long value,
java.lang.String valueName,
long minValueInclusive,
long maxValueInclusive) |
Validates that the given value is within the given range of values.
|
public static void checkNotNull(java.lang.Object obj,
java.lang.String argName)
obj - the argument reference to validate.argName - the name of the argument being validated.public static void checkPositiveInteger(long value,
java.lang.String argName)
value - the argument value to validateargName - the name of the argument being validated.public static void checkNotNegative(long value,
java.lang.String argName)
value - the argument value to validateargName - the name of the argument being validated.public static void checkRequired(boolean isPresent,
java.lang.String argName)
isPresent - indicates whether the given argument is present.argName - the name of the argument being validated.public static void checkValid(boolean isValid,
java.lang.String argName)
isValid - indicates whether the given argument is valid.argName - the name of the argument being validated.public static void checkValid(boolean isValid,
java.lang.String argName,
java.lang.String validValues)
isValid - indicates whether the given argument is valid.argName - the name of the argument being validated.validValues - the list of values that are allowed.public static void checkNotNullAndNotEmpty(java.lang.String arg,
java.lang.String argName)
arg - the argument reference to validate.argName - the name of the argument being validated.public static <T> void checkNotNullAndNotEmpty(T[] array,
java.lang.String argName)
T - the type of array's elements.array - the argument reference to validate.argName - the name of the argument being validated.public static void checkNotNullAndNotEmpty(byte[] array,
java.lang.String argName)
array - the argument reference to validate.argName - the name of the argument being validated.public static void checkNotNullAndNotEmpty(short[] array,
java.lang.String argName)
array - the argument reference to validate.argName - the name of the argument being validated.public static void checkNotNullAndNotEmpty(int[] array,
java.lang.String argName)
array - the argument reference to validate.argName - the name of the argument being validated.public static void checkNotNullAndNotEmpty(long[] array,
java.lang.String argName)
array - the argument reference to validate.argName - the name of the argument being validated.public static <T> void checkNotNullAndNotEmpty(java.lang.Iterable<T> iter,
java.lang.String argName)
T - the type of iterable's elements.iter - the argument reference to validate.argName - the name of the argument being validated.public static <T> void checkNotNullAndNumberOfElements(java.util.Collection<T> collection,
int numElements,
java.lang.String argName)
T - the type of collection's elements.collection - the argument reference to validate.numElements - the expected number of elements in the collection.argName - the name of the argument being validated.public static void checkValuesEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name)
value1 - the first value to check.value1Name - the name of the first argument.value2 - the second value to check.value2Name - the name of the second argument.public static void checkIntegerMultiple(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name)
value1 - the first value to check.value1Name - the name of the first argument.value2 - the second value to check.value2Name - the name of the second argument.public static void checkGreater(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name)
value1 - the first value to check.value1Name - the name of the first argument.value2 - the second value to check.value2Name - the name of the second argument.public static void checkGreaterOrEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name)
value1 - the first value to check.value1Name - the name of the first argument.value2 - the second value to check.value2Name - the name of the second argument.public static void checkLessOrEqual(long value1,
java.lang.String value1Name,
long value2,
java.lang.String value2Name)
value1 - the first value to check.value1Name - the name of the first argument.value2 - the second value to check.value2Name - the name of the second argument.public static void checkWithinRange(long value,
java.lang.String valueName,
long minValueInclusive,
long maxValueInclusive)
value - the value to check.valueName - the name of the argument.minValueInclusive - inclusive lower limit for the value.maxValueInclusive - inclusive upper limit for the value.public static void checkWithinRange(double value,
java.lang.String valueName,
double minValueInclusive,
double maxValueInclusive)
value - the value to check.valueName - the name of the argument.minValueInclusive - inclusive lower limit for the value.maxValueInclusive - inclusive upper limit for the value.public static void checkPathExists(java.nio.file.Path path,
java.lang.String argName)
path - the path to check.argName - the name of the argument being validated.public static void checkPathExistsAsDir(java.nio.file.Path path,
java.lang.String argName)
path - the path to check.argName - the name of the argument being validated.public static void checkPathExistsAsFile(java.nio.file.Path path,
java.lang.String argName)
path - the path to check.argName - the name of the argument being validated.public static void checkState(boolean expression,
java.lang.String format,
java.lang.Object... args)
expression - expression which must hold.format - format stringargs - arguments for the error stringjava.lang.IllegalStateException - if the state is not valid.Copyright © 2008–2025 Apache Software Foundation. All rights reserved.