@Test public void testAnd() { Validator<String> vand = v3.and(v); assertTrue(vand.test("correct")); assertFalse(vand.test("righto")); assertFalse(vand.test("coriander")); }
public final Validator<T> and(final Validator<T> other) { if (other == null) return this; final Validator<T> mine = this; return new Validator<>() { @Override public boolean test(T argument) { return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; }
Validator implements Predicate<T> { public final Validator<T> and(final Validator<T> other) { if (other == null) return this; final Validator<T> mine = this; return new Validator<>() { @Override public boolean test(T argument) { return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; } }
Validator implements Predicate<T> { public final Validator<T> and(final Validator<T> other) { if (other == null) return this; final Validator<T> mine = this; return new Validator<>() { @Override public boolean test(T argument) { return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; }  }
Validator implements Predicate<T> { public final Validator<T> and(final Validator<T> other) { if (other == null) return this; final Validator<T> mine = this; return new Validator<>() { @Override public boolean test(T argument) { return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; }  final T validate(final T argument); String invalidMessage(final T argument); final Validator<T> and(final Validator<T> other); final Validator<T> or(final Validator<T> other); final Validator<T> not(); }
Validator implements Predicate<T> { public final Validator<T> and(final Validator<T> other) { if (other == null) return this; final Validator<T> mine = this; return new Validator<>() { @Override public boolean test(T argument) { return mine.test(argument) && other.test(argument); } @Override public String invalidMessage(T argument) { return (mine.test(argument) ? other : mine).invalidMessage(argument); } }; }  final T validate(final T argument); String invalidMessage(final T argument); final Validator<T> and(final Validator<T> other); final Validator<T> or(final Validator<T> other); final Validator<T> not();  }