Class UniqueValueValidator<T>
- java.lang.Object
-
- io.github.jonestimd.swing.validation.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)
-
-
-
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 beanrequiredMessage
- the error message to use when the property is not setuniqueMessage
- 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 beanisSameGroup
- a function for testing if 2 beans are in the same group for uniquenessrequiredMessage
- the error message to use when the property is not setuniqueMessage
- 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 interfaceBeanPropertyValidator<T,java.lang.String>
- Parameters:
selectedIndex
- the index of the bean within the list of beansvalue
- the value of the property to be validateditems
- the list of beans to use for validation- Returns:
- the validation error message or null if the bean property value is valid
-
-