Package org.solidcoding.validation
Interface Validator<T>
-
public interface Validator<T>
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description <R> ReturningValidator<R>andThen(Supplier<R> supplier)Same as validate(); but returns a custom object in the form of a supplier.Validator<T>compliesWith(Predicate<T> rule)Validator<T>compliesWith(Predicate<T> rule, String failMessage)Validator<T>compliesWith(List<Predicate<T>> rules)static <T> Validator<T>makeSure(T value)TorElseReturn(Function<String,T> other)TorElseReturn(T other)<E extends RuntimeException>
booleanorElseThrow(E throwable)booleanvalidate()
-
-
-
Method Detail
-
makeSure
static <T> Validator<T> makeSure(T value)
- Type Parameters:
T- the type of the value.- Parameters:
value- the value on which to apply the rules.- Returns:
- a Validator to add rules to.
-
compliesWith
Validator<T> compliesWith(Predicate<T> rule)
- Parameters:
rule- the rule which the value needs to comply with.- Returns:
- the Validator to add more rules.
-
compliesWith
Validator<T> compliesWith(Predicate<T> rule, String failMessage)
- Parameters:
rule- the rule which the value needs to comply with.failMessage- the message to propagate to the client when breaking the rule.- Returns:
- the Validator to add more rules.
-
compliesWith
Validator<T> compliesWith(List<Predicate<T>> rules)
- Parameters:
rules- the rules which the value needs to comply with.- Returns:
- the Validator to add more rules.
-
validate
boolean validate()
- Returns:
- boolean true if all rules pass. False if at least one rule fails.
-
andThen
<R> ReturningValidator<R> andThen(Supplier<R> supplier)
Same as validate(); but returns a custom object in the form of a supplier.- Type Parameters:
R- the type you wish to return.- Parameters:
supplier- the supplier which encapsulated the return type.- Returns:
- R in the form of a supplier.
-
orElseThrow
<E extends RuntimeException> boolean orElseThrow(E throwable)
- Type Parameters:
E- the bound of the Exception that needs to be thrown when a rule is broken.- Parameters:
throwable- the Exception that needs to be thrown when a rule is broken.- Returns:
- true if all rules pass.
-
orElseReturn
T orElseReturn(T other)
- Parameters:
other- the backup/default return type if the validation fails.- Returns:
- T the return type.
-
-