ComparativeConstraint extends AbstractMultivalueConstraint<T> { public static ConstraintBuilder<Object[]> builderFor(final String regexDelimiter, final PathBuilder builder) { return new BasicConstraintBuilder<Object[]>("theid", ComparativeConstraint.class, "", Path1, Path2, CompParam) { @Override public Collection<Constraint<?>> constraintsFrom(Type type, boolean nullsAllowed, Map<String, String> values) { Path p1 = pathIn(values, Path1, regexDelimiter, builder); Path p2 = pathIn(values, Path2, regexDelimiter, builder); if (p1 == null || p2 == null) return null; Comparison comp = comparisonIn(values, CompParam); if (comp == null) return null; return withExtras( new ComparativeConstraint("asdf", p1, p2, comp), values ); } }; } ComparativeConstraint(String id, Path<T,?> op1, Path<T,?> op2, Comparison comp); static ConstraintBuilder<Object[]> builderFor(final String regexDelimiter, final PathBuilder builder); @Override String typeTag(); @Override Path[] valuePaths(); @Override Violation evaluate(Map<Path<T,?>, Object> values); static final String TypeTag; static final PathParameter Path1; static final PathParameter Path2; static final ComparisonParameter CompParam; }
@Test public void builderFor() { ConstraintBuilder<?> builder = ComparativeConstraint.builderFor(" ", SimpleAvroPath.Builder); assertNotNull(builder); Map<String,String> paramsByKey = asParams( ComparativeConstraint.Path1, "birthdate", ComparativeConstraint.Path2, "deathdate", ComparativeConstraint.CompParam, ">" ); Collection<Constraint<?>> constraints = builder.constraintsFrom(null, false, paramsByKey); assertNotNull(constraints); Constraint<?> cst = constraints.iterator().next(); assertNotNull(cst); }