@Test public void testRange() throws Exception { final Validation validation = Length.range(2, 4); assertFalse(validation.isValid("a")); assertTrue(validation.isValid("ab")); assertTrue(validation.isValid("abc")); assertTrue(validation.isValid("abcd")); assertFalse(validation.isValid("abcde")); }
public static Validation range(final int minLength, final int maxLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } if (maxLength <= 0) { throw new IllegalArgumentException("maxLength must be positive"); } return new Length(minLength, maxLength); }
Length implements Validation { public static Validation range(final int minLength, final int maxLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } if (maxLength <= 0) { throw new IllegalArgumentException("maxLength must be positive"); } return new Length(minLength, maxLength); } }
Length implements Validation { public static Validation range(final int minLength, final int maxLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } if (maxLength <= 0) { throw new IllegalArgumentException("maxLength must be positive"); } return new Length(minLength, maxLength); } private  Length(final int minLength, final int maxLength); }
Length implements Validation { public static Validation range(final int minLength, final int maxLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } if (maxLength <= 0) { throw new IllegalArgumentException("maxLength must be positive"); } return new Length(minLength, maxLength); } private  Length(final int minLength, final int maxLength); static Validation min(final int minLength); static Validation max(final int maxLength); static Validation range(final int minLength, final int maxLength); @Override String getErrorMessage(final Context context); @Override boolean isValid(final String text); }
Length implements Validation { public static Validation range(final int minLength, final int maxLength) { if (minLength <= 0) { throw new IllegalArgumentException("minLength must be positive"); } if (maxLength <= 0) { throw new IllegalArgumentException("maxLength must be positive"); } return new Length(minLength, maxLength); } private  Length(final int minLength, final int maxLength); static Validation min(final int minLength); static Validation max(final int maxLength); static Validation range(final int minLength, final int maxLength); @Override String getErrorMessage(final Context context); @Override boolean isValid(final String text);  }