summaryrefslogtreecommitdiff
path: root/lib/java/src/main/java/org/apache/thrift/partial/Validate.java
diff options
context:
space:
mode:
Diffstat (limited to 'lib/java/src/main/java/org/apache/thrift/partial/Validate.java')
-rw-r--r--lib/java/src/main/java/org/apache/thrift/partial/Validate.java140
1 files changed, 34 insertions, 106 deletions
diff --git a/lib/java/src/main/java/org/apache/thrift/partial/Validate.java b/lib/java/src/main/java/org/apache/thrift/partial/Validate.java
index ef0466a5e..f4bbd9a5a 100644
--- a/lib/java/src/main/java/org/apache/thrift/partial/Validate.java
+++ b/lib/java/src/main/java/org/apache/thrift/partial/Validate.java
@@ -26,30 +26,24 @@ import java.util.Collection;
/**
* A superset of Validate class in Apache commons lang3.
*
- * 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.
+ * <p>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.
*/
public final class Validate {
private Validate() {}
- /**
- * Validates that the given reference argument is not null.
- */
+ /** Validates that the given reference argument is not null. */
public static void checkNotNull(Object obj, String argName) {
checkArgument(obj != null, "'%s' must not be null.", argName);
}
- /**
- * Validates that the given integer argument is not zero or negative.
- */
+ /** Validates that the given integer argument is not zero or negative. */
public static void checkPositiveInteger(long value, String argName) {
checkArgument(value > 0, "'%s' must be a positive integer.", argName);
}
- /**
- * Validates that the given integer argument is not negative.
- */
+ /** Validates that the given integer argument is not negative. */
public static void checkNotNegative(long value, String argName) {
checkArgument(value >= 0, "'%s' must not be negative.", argName);
}
@@ -61,83 +55,60 @@ public final class Validate {
checkArgument(isPresent, "'%s' is required.", argName);
}
- /**
- * Validates that the expression (that checks a field is valid) is true.
- */
+ /** Validates that the expression (that checks a field is valid) is true. */
public static void checkValid(boolean isValid, String argName) {
checkArgument(isValid, "'%s' is invalid.", argName);
}
- /**
- * Validates that the expression (that checks a field is valid) is true.
- */
+ /** Validates that the expression (that checks a field is valid) is true. */
public static void checkValid(boolean isValid, String argName, String validValues) {
checkArgument(isValid, "'%s' is invalid. Valid values are: %s.", argName, validValues);
}
- /**
- * Validates that the given string is not null and has non-zero length.
- */
+ /** Validates that the given string is not null and has non-zero length. */
public static void checkNotNullAndNotEmpty(String arg, String argName) {
Validate.checkNotNull(arg, argName);
- Validate.checkArgument(
- arg.length() > 0,
- "'%s' must not be empty.",
- argName);
+ Validate.checkArgument(arg.length() > 0, "'%s' must not be empty.", argName);
}
- /**
- * Validates that the given array is not null and has at least one element.
- */
+ /** Validates that the given array is not null and has at least one element. */
public static <T> void checkNotNullAndNotEmpty(T[] array, String argName) {
Validate.checkNotNull(array, argName);
checkNotEmpty(array.length, argName);
}
- /**
- * Validates that the given array is not null and has at least one element.
- */
+ /** Validates that the given array is not null and has at least one element. */
public static void checkNotNullAndNotEmpty(byte[] array, String argName) {
Validate.checkNotNull(array, argName);
checkNotEmpty(array.length, argName);
}
- /**
- * Validates that the given array is not null and has at least one element.
- */
+ /** Validates that the given array is not null and has at least one element. */
public static void checkNotNullAndNotEmpty(short[] array, String argName) {
Validate.checkNotNull(array, argName);
checkNotEmpty(array.length, argName);
}
- /**
- * Validates that the given array is not null and has at least one element.
- */
+ /** Validates that the given array is not null and has at least one element. */
public static void checkNotNullAndNotEmpty(int[] array, String argName) {
Validate.checkNotNull(array, argName);
checkNotEmpty(array.length, argName);
}
- /**
- * Validates that the given array is not null and has at least one element.
- */
+ /** Validates that the given array is not null and has at least one element. */
public static void checkNotNullAndNotEmpty(long[] array, String argName) {
Validate.checkNotNull(array, argName);
checkNotEmpty(array.length, argName);
}
- /**
- * Validates that the given buffer is not null and has non-zero capacity.
- */
+ /** Validates that the given buffer is not null and has non-zero capacity. */
public static <T> void checkNotNullAndNotEmpty(Iterable<T> iter, String argName) {
Validate.checkNotNull(iter, argName);
int minNumElements = iter.iterator().hasNext() ? 1 : 0;
checkNotEmpty(minNumElements, argName);
}
- /**
- * Validates that the given set is not null and has an exact number of items.
- */
+ /** Validates that the given set is not null and has an exact number of items. */
public static <T> void checkNotNullAndNumberOfElements(
Collection<T> collection, int numElements, String argName) {
Validate.checkNotNull(collection, argName);
@@ -146,18 +117,12 @@ public final class Validate {
"Number of elements in '%s' must be exactly %s, %s given.",
argName,
numElements,
- collection.size()
- );
+ collection.size());
}
- /**
- * Validates that the given two values are equal.
- */
+ /** Validates that the given two values are equal. */
public static void checkValuesEqual(
- long value1,
- String value1Name,
- long value2,
- String value2Name) {
+ long value1, String value1Name, long value2, String value2Name) {
checkArgument(
value1 == value2,
"'%s' (%s) must equal '%s' (%s).",
@@ -167,14 +132,9 @@ public final class Validate {
value2);
}
- /**
- * Validates that the first value is an integer multiple of the second value.
- */
+ /** Validates that the first value is an integer multiple of the second value. */
public static void checkIntegerMultiple(
- long value1,
- String value1Name,
- long value2,
- String value2Name) {
+ long value1, String value1Name, long value2, String value2Name) {
checkArgument(
(value1 % value2) == 0,
"'%s' (%s) must be an integer multiple of '%s' (%s).",
@@ -184,14 +144,8 @@ public final class Validate {
value2);
}
- /**
- * Validates that the first value is greater than the second value.
- */
- public static void checkGreater(
- long value1,
- String value1Name,
- long value2,
- String value2Name) {
+ /** Validates that the first value is greater than the second value. */
+ public static void checkGreater(long value1, String value1Name, long value2, String value2Name) {
checkArgument(
value1 > value2,
"'%s' (%s) must be greater than '%s' (%s).",
@@ -201,14 +155,9 @@ public final class Validate {
value2);
}
- /**
- * Validates that the first value is greater than or equal to the second value.
- */
+ /** Validates that the first value is greater than or equal to the second value. */
public static void checkGreaterOrEqual(
- long value1,
- String value1Name,
- long value2,
- String value2Name) {
+ long value1, String value1Name, long value2, String value2Name) {
checkArgument(
value1 >= value2,
"'%s' (%s) must be greater than or equal to '%s' (%s).",
@@ -218,14 +167,9 @@ public final class Validate {
value2);
}
- /**
- * Validates that the first value is less than or equal to the second value.
- */
+ /** Validates that the first value is less than or equal to the second value. */
public static void checkLessOrEqual(
- long value1,
- String value1Name,
- long value2,
- String value2Name) {
+ long value1, String value1Name, long value2, String value2Name) {
checkArgument(
value1 <= value2,
"'%s' (%s) must be less than or equal to '%s' (%s).",
@@ -235,14 +179,9 @@ public final class Validate {
value2);
}
- /**
- * Validates that the given value is within the given range of values.
- */
+ /** Validates that the given value is within the given range of values. */
public static void checkWithinRange(
- long value,
- String valueName,
- long minValueInclusive,
- long maxValueInclusive) {
+ long value, String valueName, long minValueInclusive, long maxValueInclusive) {
checkArgument(
(value >= minValueInclusive) && (value <= maxValueInclusive),
"'%s' (%s) must be within the range [%s, %s].",
@@ -252,14 +191,9 @@ public final class Validate {
maxValueInclusive);
}
- /**
- * Validates that the given value is within the given range of values.
- */
+ /** Validates that the given value is within the given range of values. */
public static void checkWithinRange(
- double value,
- String valueName,
- double minValueInclusive,
- double maxValueInclusive) {
+ double value, String valueName, double minValueInclusive, double maxValueInclusive) {
checkArgument(
(value >= minValueInclusive) && (value <= maxValueInclusive),
"'%s' (%s) must be within the range [%s, %s].",
@@ -277,10 +211,7 @@ public final class Validate {
public static void checkPathExistsAsDir(Path path, String argName) {
checkPathExists(path, argName);
checkArgument(
- Files.isDirectory(path),
- "Path %s (%s) must point to a directory.",
- argName,
- path);
+ Files.isDirectory(path), "Path %s (%s) must point to a directory.", argName, path);
}
public static void checkPathExistsAsFile(Path path, String argName) {
@@ -297,9 +228,6 @@ public final class Validate {
}
private static void checkNotEmpty(int arraySize, String argName) {
- Validate.checkArgument(
- arraySize > 0,
- "'%s' must have at least one element.",
- argName);
+ Validate.checkArgument(arraySize > 0, "'%s' must have at least one element.", argName);
}
}