summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2022-03-30 14:02:29 +0200
committerJon Marius Venstad <venstad@gmail.com>2022-03-30 14:02:29 +0200
commitd9a7ccfb233dd4104dc50f759e5c84f5581a6f71 (patch)
treea3c4c4b4335565b81af58a966ba83996e7d490bf /vespajlib
parenta86835cf73cab55ca04932ee305f9653bce2ceb8 (diff)
Fix javadoc
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/src/main/java/ai/vespa/validation/Validation.java21
1 files changed, 10 insertions, 11 deletions
diff --git a/vespajlib/src/main/java/ai/vespa/validation/Validation.java b/vespajlib/src/main/java/ai/vespa/validation/Validation.java
index b494b3634f7..2dc30efabe3 100644
--- a/vespajlib/src/main/java/ai/vespa/validation/Validation.java
+++ b/vespajlib/src/main/java/ai/vespa/validation/Validation.java
@@ -4,13 +4,12 @@ package ai.vespa.validation;
import com.yahoo.yolean.Exceptions;
import java.util.function.Function;
-import java.util.function.Predicate;
import java.util.regex.Pattern;
import static java.util.Objects.requireNonNull;
/**
- * Every {@link String} is a security risk!
+ * Every raw {@link String} is a potential bug, and a security risk!
* This class has utility methods for validating strings, which are often user input.
*
* @author jonmv
@@ -19,7 +18,7 @@ public class Validation {
private Validation() { }
- /** Parses then given string, and then validates that each of the requirements are true for the parsed value. */
+ /** Parses and returns the given string, or throws an exception with some context in the message. */
public static <T> T parse(String value, Function<String, T> parser, String description) {
try {
return parser.apply(requireNonNull(value, description + " cannot be null"));
@@ -30,27 +29,27 @@ public class Validation {
}
}
- /** Requires arguments to match the given pattern. */
+ /** Requires the value to match the given pattern. */
public static String requireMatch(String value, String description, Pattern pattern) {
return require(pattern.matcher(value).matches(), value, description, "must match '" + pattern + "'");
}
- /** Requires arguments to be non-blank. */
+ /** Requires the value to be non-blank. */
public static String requireNonBlank(String value, String description) {
return require( ! value.isBlank(), value, description, "cannot be blank");
}
- /** Requires arguments to be at least the lower bound. */
+ /** Requires the value to be at least the lower bound. */
public static <T extends Comparable<? super T>> T requireAtLeast(T value, String description, T lower) {
return require(lower.compareTo(value) <= 0, value, description, "must be at least '" + lower + "'");
}
- /** Requires arguments to be at most the upper bound. */
+ /** Requires the value to be at most the upper bound. */
public static <T extends Comparable<? super T>> T requireAtMost(T value, String description, T upper) {
return require(upper.compareTo(value) >= 0, value, description, "must be at most '" + upper + "'");
}
- /** Requires arguments to be at least the lower bound, and at most the upper bound. */
+ /** Requires the value to be at least the lower bound, and at most the upper bound. */
public static <T extends Comparable<? super T>> T requireInRange(T value, String description, T lower, T upper) {
if (lower.compareTo(upper) > 0) throw new IllegalArgumentException("lower bound cannot be greater than upper bound, " +
"but got '" + lower + "' > '" + upper + "'");
@@ -58,10 +57,10 @@ public class Validation {
"must be at least '" + lower + "' and at most '" + upper + "'");
}
- /** Wraps a predicate with a message describing it. */
- public static <T> T require(boolean condition, T value, String description, String message) {
+ /** Returns the argument if the condition is true, otherwise throws. */
+ public static <T> T require(boolean condition, T value, String description, String requirement) {
if (condition) return value;
- throw new IllegalArgumentException(description + " " + message + ", but got: '" + value + "'");
+ throw new IllegalArgumentException(description + " " + requirement + ", but got: '" + value + "'");
}
} \ No newline at end of file