Class BeanValidationUtils

java.lang.Object
dev.orne.beans.BeanValidationUtils

@API(status=STABLE, since="0.1") public final class BeanValidationUtils extends Object
Utility class for bean validations.
Since:
0.1
Version:
1.0, 2020-05
Author:
(w) Iker Hernaez
  • Method Summary

    Modifier and Type
    Method
    Description
    static javax.validation.Validator
    Returns the shared Validator used to validate beans.
    static boolean
    isValid(@NotNull Object obj, @NotNull Class<?>... groups)
    Validates if the specified bean is valid for the specified validation groups.
    static boolean
    Validates if the specified bean has a valid, non null, identity.
    static boolean
    Validates if the specified bean is a valid bean reference.
    static void
    setValidator(@NotNull javax.validation.Validator validator)
    Sets the shared Validator used to validate beans.
    static <T> @NotNull Set<javax.validation.ConstraintViolation<T>>
    validate(T obj, @NotNull Class<?>... groups)
    Validates the specified bean for the specified validation groups.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getValidator

      public static javax.validation.Validator getValidator()
      Returns the shared Validator used to validate beans.
      Returns:
      The shared Validator used to validate beans
    • setValidator

      public static void setValidator(@NotNull @NotNull javax.validation.Validator validator)
      Sets the shared Validator used to validate beans.
      Parameters:
      validator - The shared Validator used to validate beans
    • isValid

      public static boolean isValid(@NotNull @NotNull Object obj, @NotNull @NotNull Class<?>... groups)
      Validates if the specified bean is valid for the specified validation groups.
      Parameters:
      obj - The bean to validate
      groups - The group or list of groups targeted for validation (defaults to Default)
      Returns:
      If the object is valid for the specified groups
      Throws:
      IllegalArgumentException - if object is null or if null is passed to the varargs groups
      javax.validation.ValidationException - if a non recoverable error happens during the validation process
    • isValidBeanIdentity

      public static boolean isValidBeanIdentity(@NotNull @NotNull Object obj)
      Validates if the specified bean has a valid, non null, identity.
      Parameters:
      obj - The bean to validate
      Returns:
      If the bean has a valid identity
      Throws:
      IllegalArgumentException - if bean is null
      javax.validation.ValidationException - if a non recoverable error happens during the validation process
    • isValidBeanReference

      public static boolean isValidBeanReference(@NotNull @NotNull Object obj)
      Validates if the specified bean is a valid bean reference.
      Parameters:
      obj - The bean to validate
      Returns:
      If the bean is a valid bean reference
      Throws:
      IllegalArgumentException - if bean is null
      javax.validation.ValidationException - if a non recoverable error happens during the validation process
    • validate

      @NotNull public static <T> @NotNull Set<javax.validation.ConstraintViolation<T>> validate(@NotNull T obj, @NotNull @NotNull Class<?>... groups)
      Validates the specified bean for the specified validation groups.
      Type Parameters:
      T - The type of bean to validate
      Parameters:
      obj - The bean to validate
      groups - The group or list of groups targeted for validation (defaults to Default)
      Returns:
      The constraint violations or an empty set if none
      Throws:
      IllegalArgumentException - if object is null or if null is passed to the varargs groups
      javax.validation.ValidationException - if a non recoverable error happens during the validation process