Package ai.vespa.validation
Class Validation
java.lang.Object
ai.vespa.validation.Validation
Every raw
String
is a potential bug, and a security risk!
This class has utility methods for validating strings, which are often user input.- Author:
- jonmv
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
Parses and returns the given string, or throws an exception with some context in the message.static <T> T
Returns the argument if the condition is true, otherwise throws.static <T extends Comparable<? super T>>
TrequireAtLeast
(T value, String description, T lower) Requires the value to be at least the lower bound.static <T extends Comparable<? super T>>
TrequireAtMost
(T value, String description, T upper) Requires the value to be at most the upper bound.static <T extends Comparable<? super T>>
TrequireInRange
(T value, String description, T lower, T upper) Requires the value to be at least the lower bound, and at most the upper bound.static String
requireLength
(String value, String description, int lower, int upper) Requires the value to have a length in range lower to upper, inclusive.static String
requireMatch
(String value, String description, Pattern pattern) Requires the value to match the given pattern.static String
requireNonBlank
(String value, String description) Requires the value to be non-blank.
-
Method Details
-
parse
Parses and returns the given string, or throws an exception with some context in the message. -
requireLength
Requires the value to have a length in range lower to upper, inclusive. -
requireMatch
Requires the value to match the given pattern. -
requireNonBlank
Requires the value to be non-blank. -
requireAtLeast
public static <T extends Comparable<? super T>> T requireAtLeast(T value, String description, T lower) Requires the value to be at least the lower bound. -
requireAtMost
public static <T extends Comparable<? super T>> T requireAtMost(T value, String description, T upper) Requires the value to be at most the upper bound. -
requireInRange
public static <T extends Comparable<? super T>> T requireInRange(T value, String description, T lower, T upper) Requires the value to be at least the lower bound, and at most the upper bound. -
require
Returns the argument if the condition is true, otherwise throws.
-