@Test public void test_validate() { CobolFieldPatternValidator validator = new CobolFieldPatternValidator(); assertTrue(validator.validate("X")); assertTrue(validator.validate("XX")); assertFalse(validator.validate("X(0)")); assertTrue(validator.validate("X(2)")); assertTrue(validator.validate("X(22)")); assertFalse(validator.validate("X(00)")); assertTrue(validator.validate("x")); assertTrue(validator.validate("xx")); assertTrue(validator.validate("x(2)")); assertTrue(validator.validate("x(22)")); assertTrue(validator.validate("X(4)")); assertTrue(validator.validate("X(30)")); assertTrue(validator.validate("X(307)")); assertTrue(validator.validate("9")); assertTrue(validator.validate("99")); assertFalse(validator.validate("99(2)")); assertFalse(validator.validate("9(0)")); assertTrue(validator.validate("9(2)")); assertTrue(validator.validate("9(20)")); assertTrue(validator.validate("9(2)")); assertTrue(validator.validate("9(22)")); assertTrue(validator.validate("9(202)")); assertTrue(validator.validate("9v9")); assertTrue(validator.validate("9v99")); assertTrue(validator.validate("99v9")); assertFalse(validator.validate("9(0)v9")); assertFalse(validator.validate("99(2)v9")); assertTrue(validator.validate("9(2)v9")); assertTrue(validator.validate("9(20)v9")); assertTrue(validator.validate("9(22)v9")); assertTrue(validator.validate("9(202)v9")); assertTrue(validator.validate("9(2)v99")); assertFalse(validator.validate("99(2)v99(2)")); assertFalse(validator.validate("9(0)v9(0)")); assertFalse(validator.validate("9(00)v9(0)")); assertFalse(validator.validate("9(0)v9(00)")); assertFalse(validator.validate("9(00)v9(00)")); assertTrue(validator.validate("9(2)v9(2)")); assertTrue(validator.validate("9(20)v9(20)")); assertFalse(validator.validate("9v99(2)")); assertFalse(validator.validate("9v9(0)")); assertFalse(validator.validate("9v9(000)")); assertTrue(validator.validate("9v9(2)")); assertTrue(validator.validate("9v9(202)")); assertTrue(validator.validate("9v9(20)")); assertTrue(validator.validate("9(22)v9(22)")); assertTrue(validator.validate("9(202)v9(202)")); assertTrue(validator.validate("9(2)V9")); }
public boolean validate(String pattern) { List patterns = Arrays.asList(new String[]{ALPHANUMERIC_PATTERN, INTEGER_PATTERN, DECIMAL_PATTERN}); Iterator it = patterns.iterator(); while (it.hasNext()) { if (Pattern.matches((String) it.next(), pattern)) { return true; } } return false; }
CobolFieldPatternValidator { public boolean validate(String pattern) { List patterns = Arrays.asList(new String[]{ALPHANUMERIC_PATTERN, INTEGER_PATTERN, DECIMAL_PATTERN}); Iterator it = patterns.iterator(); while (it.hasNext()) { if (Pattern.matches((String) it.next(), pattern)) { return true; } } return false; } }
CobolFieldPatternValidator { public boolean validate(String pattern) { List patterns = Arrays.asList(new String[]{ALPHANUMERIC_PATTERN, INTEGER_PATTERN, DECIMAL_PATTERN}); Iterator it = patterns.iterator(); while (it.hasNext()) { if (Pattern.matches((String) it.next(), pattern)) { return true; } } return false; }  }
CobolFieldPatternValidator { public boolean validate(String pattern) { List patterns = Arrays.asList(new String[]{ALPHANUMERIC_PATTERN, INTEGER_PATTERN, DECIMAL_PATTERN}); Iterator it = patterns.iterator(); while (it.hasNext()) { if (Pattern.matches((String) it.next(), pattern)) { return true; } } return false; }  boolean validate(String pattern); }
CobolFieldPatternValidator { public boolean validate(String pattern) { List patterns = Arrays.asList(new String[]{ALPHANUMERIC_PATTERN, INTEGER_PATTERN, DECIMAL_PATTERN}); Iterator it = patterns.iterator(); while (it.hasNext()) { if (Pattern.matches((String) it.next(), pattern)) { return true; } } return false; }  boolean validate(String pattern); static final String ALPHANUMERIC_PATTERN; static final String INTEGER_PATTERN; static final String DECIMAL_PATTERN; }