@Test public void test_ipv4_matcher() { DividedStringPatternMatcher matcherToTest = new DividedStringPatternMatcher("54.*.*.*", '.'); assertFalse(matcherToTest.isMatching("1.2.3")); assertFalse(matcherToTest.isMatching("1.2.3.4")); assertFalse(matcherToTest.isMatching("55.2.3.4")); assertFalse(matcherToTest.isMatching("54")); assertFalse(matcherToTest.isMatching("")); assertFalse(matcherToTest.isMatching(null)); assertFalse(matcherToTest.isMatching("54.2.3.")); assertTrue(matcherToTest.isMatching("54.2.3.4")); assertTrue(matcherToTest.isMatching("54.2.3.255")); assertTrue(matcherToTest.isMatching("54.255.255.255")); }
public boolean isMatching(String given ) { if (given==null) { return false; } String target = given.toLowerCase(); String[] targetPart = splitByDivider(target); if (targetPart == null) { return false; } if (targetPart.length != patternParts.length) { return false; } boolean accepted = true; for (int i = 0; i < patternParts.length && accepted; i++) { accepted = patternParts[i].equals("*") || patternParts[i].equals(targetPart[i]); } return accepted; }
DividedStringPatternMatcher { public boolean isMatching(String given ) { if (given==null) { return false; } String target = given.toLowerCase(); String[] targetPart = splitByDivider(target); if (targetPart == null) { return false; } if (targetPart.length != patternParts.length) { return false; } boolean accepted = true; for (int i = 0; i < patternParts.length && accepted; i++) { accepted = patternParts[i].equals("*") || patternParts[i].equals(targetPart[i]); } return accepted; } }
DividedStringPatternMatcher { public boolean isMatching(String given ) { if (given==null) { return false; } String target = given.toLowerCase(); String[] targetPart = splitByDivider(target); if (targetPart == null) { return false; } if (targetPart.length != patternParts.length) { return false; } boolean accepted = true; for (int i = 0; i < patternParts.length && accepted; i++) { accepted = patternParts[i].equals("*") || patternParts[i].equals(targetPart[i]); } return accepted; } DividedStringPatternMatcher(String pattern, char divider); }
DividedStringPatternMatcher { public boolean isMatching(String given ) { if (given==null) { return false; } String target = given.toLowerCase(); String[] targetPart = splitByDivider(target); if (targetPart == null) { return false; } if (targetPart.length != patternParts.length) { return false; } boolean accepted = true; for (int i = 0; i < patternParts.length && accepted; i++) { accepted = patternParts[i].equals("*") || patternParts[i].equals(targetPart[i]); } return accepted; } DividedStringPatternMatcher(String pattern, char divider); String[] getPatternParts(); boolean isMatching(String given ); }
DividedStringPatternMatcher { public boolean isMatching(String given ) { if (given==null) { return false; } String target = given.toLowerCase(); String[] targetPart = splitByDivider(target); if (targetPart == null) { return false; } if (targetPart.length != patternParts.length) { return false; } boolean accepted = true; for (int i = 0; i < patternParts.length && accepted; i++) { accepted = patternParts[i].equals("*") || patternParts[i].equals(targetPart[i]); } return accepted; } DividedStringPatternMatcher(String pattern, char divider); String[] getPatternParts(); boolean isMatching(String given );  }