@Test public void testMatches() throws Exception { NumberInRangeMatcher matcher = new NumberInRangeMatcher(); assertTrue(matcher.matches("32", "32")); assertTrue(matcher.matches("32", "12 32")); assertTrue(matcher.matches("32", "32 9")); assertTrue(matcher.matches("32", "12 32-33 89")); assertTrue(matcher.matches("32", "12 31-32 89")); assertTrue(matcher.matches("32", "12 31-33 89")); assertTrue(matcher.matches("32", "12-18 30-35 45-90")); assertTrue(matcher.matches("1854", "Vols. 1-7, 1848-1868 etc.")); assertFalse(matcher.matches("29", "32")); assertFalse(matcher.matches("29", "12 32")); assertFalse(matcher.matches("29", "32 9")); assertFalse(matcher.matches("29", "12 32-33 89")); assertFalse(matcher.matches("29", "12 31-32 89")); assertFalse(matcher.matches("29", "12 31-33 89")); assertFalse(matcher.matches("29", "12-18 30-35 45-90")); assertFalse(matcher.matches("1829", "Vols. 1-7, 1848-1868 etc.")); assertTrue(matcher.matches("32", "12 32/33 89")); assertTrue(matcher.matches("33", "12 32/33 89")); assertTrue(matcher.matches("32", "12 31-3 89")); assertTrue(matcher.matches("1332", "12 1331-3 89")); assertTrue(matcher.matches("1332", "12 1331-33 89")); assertTrue(matcher.matches("1332", "12 1331-333 89")); assertFalse(matcher.matches("33", "12 32/34 89")); assertTrue(matcher.matches("31", "88 12+ 32/33 89")); assertTrue(matcher.matches("1888", "88 12+ 1832+ 89")); }
@Override public boolean matches(String s1, String s2) { if (s1 == null && s2 == null) return true; if (s1 == null || s1.length() == 0) return false; int n; try { n = Integer.parseInt(s1); } catch (NumberFormatException e) { return false; } for (int[] range : findRanges(s2)) { if (range[0] <= n && n <= range[1]) { return true; } } return false; }
NumberInRangeMatcher implements Matcher { @Override public boolean matches(String s1, String s2) { if (s1 == null && s2 == null) return true; if (s1 == null || s1.length() == 0) return false; int n; try { n = Integer.parseInt(s1); } catch (NumberFormatException e) { return false; } for (int[] range : findRanges(s2)) { if (range[0] <= n && n <= range[1]) { return true; } } return false; } }
NumberInRangeMatcher implements Matcher { @Override public boolean matches(String s1, String s2) { if (s1 == null && s2 == null) return true; if (s1 == null || s1.length() == 0) return false; int n; try { n = Integer.parseInt(s1); } catch (NumberFormatException e) { return false; } for (int[] range : findRanges(s2)) { if (range[0] <= n && n <= range[1]) { return true; } } return false; }  }
NumberInRangeMatcher implements Matcher { @Override public boolean matches(String s1, String s2) { if (s1 == null && s2 == null) return true; if (s1 == null || s1.length() == 0) return false; int n; try { n = Integer.parseInt(s1); } catch (NumberFormatException e) { return false; } for (int[] range : findRanges(s2)) { if (range[0] <= n && n <= range[1]) { return true; } } return false; }  @Override boolean matches(String s1, String s2); @Override boolean isExact(); @Override String getExecutionReport(); @Override int getCost(); }
NumberInRangeMatcher implements Matcher { @Override public boolean matches(String s1, String s2) { if (s1 == null && s2 == null) return true; if (s1 == null || s1.length() == 0) return false; int n; try { n = Integer.parseInt(s1); } catch (NumberFormatException e) { return false; } for (int[] range : findRanges(s2)) { if (range[0] <= n && n <= range[1]) { return true; } } return false; }  @Override boolean matches(String s1, String s2); @Override boolean isExact(); @Override String getExecutionReport(); @Override int getCost();  }