Class Validation

java.lang.Object
ai.vespa.validation.Validation

public class Validation extends Object
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 Details

    • parse

      public static <T> T parse(String value, Function<String,T> parser, String description)
      Parses and returns the given string, or throws an exception with some context in the message.
    • requireLength

      public static String requireLength(String value, String description, int lower, int upper)
      Requires the value to have a length in range lower to upper, inclusive.
    • requireMatch

      public static String requireMatch(String value, String description, Pattern pattern)
      Requires the value to match the given pattern.
    • requireNonBlank

      public static String requireNonBlank(String value, String description)
      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

      public static <T> T require(boolean condition, T value, String description)
      Returns the argument if the condition is true, otherwise throws.