public ValidationException[] apply(String value) { try { return result(getPredicate().evaluate(correct(value)), value); } catch (ValidationException e) { return failed(e); } }
@Override public String toString() { return getDescription(); }
/** * Creates a new primitive rule * @param predicate predicate to be used * @param trimmer trimming behavior */ public PredicatePrimitiveTypeRule(Predicate predicate, Trimmer trimmer) { this.predicate = predicate; this.trimmer = trimmer; setDescription("Primitive value '%s' requires to be " + predicate.getDescription()); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with leading whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder leftTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.LEFT))); }
public boolean test(String value) { try { return getPredicate().evaluate(value); } catch (ValidationException e) { return false; } }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with trailing whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder rightTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.RIGHT))); }
public boolean test(String value) { try { return getPredicate().evaluate(value); } catch (ValidationException e) { return false; } }
public ValidationException[] apply(String value) { try { return result(getPredicate().evaluate(correct(value)), value); } catch (ValidationException e) { return failed(e); } }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder is(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate))); }
/** * Creates a new primitive rule * @param predicate predicate to be used * @param trimmer trimming behavior */ public PredicatePrimitiveTypeRule(Predicate predicate, Trimmer trimmer) { this.predicate = predicate; this.trimmer = trimmer; setDescription("Primitive value '%s' requires to be " + predicate.getDescription()); }
@Override public String toString() { return getDescription(); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with trailing whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder rightTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.RIGHT))); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with leading and trailing whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder allTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.ALL))); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder is(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate))); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with leading and trailing whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder allTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.ALL))); }
/** * Builds a {@link PrimitiveTypeRule} that evaluates the specified {@link Predicate} against the * primitive value with leading whitespaces trimmed. * * @param predicate predicate to evaluate the primitive value against * * @return this instance to build more rules */ public PrimitiveRuleBuilder leftTrim(Predicate predicate) { return test(prepareRule(new PredicatePrimitiveTypeRule(predicate, Trimmer.LEFT))); }