Class UniqueValueValidator<T>

  • Type Parameters:
    T - the class of the beans
    All Implemented Interfaces:
    BeanPropertyValidator<T,​java.lang.String>

    public class UniqueValueValidator<T>
    extends java.lang.Object
    implements BeanPropertyValidator<T,​java.lang.String>
    Validate a property of a bean for uniqueness within a list of beans of the same type.
    • Constructor Summary

      Constructors 
      Constructor Description
      UniqueValueValidator​(java.util.function.Function<? super T,​java.lang.String> beanAdapter, java.lang.String requiredMessage, java.lang.String uniqueMessage)
      Construct a validator that uses all beans in the list for validating uniqueness.
      UniqueValueValidator​(java.util.function.Function<? super T,​java.lang.String> beanAdapter, java.util.function.BiFunction<? super T,​? super T,​java.lang.Boolean> isSameGroup, java.lang.String requiredMessage, java.lang.String uniqueMessage)
      Construct a validator that uses all beans in the list for validating uniqueness.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String validate​(int selectedIndex, java.lang.String value, java.util.List<? extends T> items)
      Validate a property of a bean from a list of beans.
      java.lang.String validate​(T selectedItem, java.lang.String value, java.lang.Iterable<? extends T> items)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UniqueValueValidator

        public UniqueValueValidator​(java.util.function.Function<? super T,​java.lang.String> beanAdapter,
                                    java.lang.String requiredMessage,
                                    java.lang.String uniqueMessage)
        Construct a validator that uses all beans in the list for validating uniqueness.
        Parameters:
        beanAdapter - the function for getting the property value from a bean
        requiredMessage - the error message to use when the property is not set
        uniqueMessage - the error message to use when the property value is not unique
      • UniqueValueValidator

        public UniqueValueValidator​(java.util.function.Function<? super T,​java.lang.String> beanAdapter,
                                    java.util.function.BiFunction<? super T,​? super T,​java.lang.Boolean> isSameGroup,
                                    java.lang.String requiredMessage,
                                    java.lang.String uniqueMessage)
        Construct a validator that uses all beans in the list for validating uniqueness.
        Parameters:
        beanAdapter - the function for getting the property value from a bean
        isSameGroup - a function for testing if 2 beans are in the same group for uniqueness
        requiredMessage - the error message to use when the property is not set
        uniqueMessage - the error message to use when the property value is not unique
    • Method Detail

      • validate

        public java.lang.String validate​(int selectedIndex,
                                         java.lang.String value,
                                         java.util.List<? extends T> items)
        Description copied from interface: BeanPropertyValidator
        Validate a property of a bean from a list of beans.
        Specified by:
        validate in interface BeanPropertyValidator<T,​java.lang.String>
        Parameters:
        selectedIndex - the index of the bean within the list of beans
        value - the value of the property to be validated
        items - the list of beans to use for validation
        Returns:
        the validation error message or null if the bean property value is valid
      • validate

        public java.lang.String validate​(T selectedItem,
                                         java.lang.String value,
                                         java.lang.Iterable<? extends T> items)