@Test public void overlaps() { assertTrue(Numerical.overlaps("667", 666, 668)); assertTrue(Numerical.overlaps("667-700", 666, 668)); assertTrue(Numerical.overlaps("660-667", 666, 668)); assertTrue(Numerical.overlaps("668-680", 666, 668)); assertTrue(Numerical.overlaps("600-666", 666, 668)); assertFalse(Numerical.overlaps("777", 666, 668)); assertFalse(Numerical.overlaps("700-707", 666, 668)); assertFalse(Numerical.overlaps("600", 666, 668)); assertFalse(Numerical.overlaps("600-606", 666, 668)); assertTrue(Numerical.overlaps("665-669", 666, 668)); }
public static boolean overlaps(String input, Integer start, Integer end) { Integer startValue = start; Integer endValue = end; Integer minPos = null; Integer maxPos = null; boolean overlap = false; List<Integer> positions = extractPositiveIntegers(input); if (positions.size() > 0) { minPos = Collections.min(positions); maxPos = Collections.max(positions); } NumberRange range; if (startValue != null) { if (endValue == null || endValue < startValue) { endValue = startValue; } range = new NumberRange(startValue, endValue); if (range.containsNumber(minPos) || range.containsNumber(maxPos)) { overlap = true; } } if (minPos != null && maxPos != null) { range = new NumberRange(minPos, maxPos); if (range.containsNumber(startValue) || range.containsNumber(endValue)) { overlap = true; } } return overlap; }
Numerical { public static boolean overlaps(String input, Integer start, Integer end) { Integer startValue = start; Integer endValue = end; Integer minPos = null; Integer maxPos = null; boolean overlap = false; List<Integer> positions = extractPositiveIntegers(input); if (positions.size() > 0) { minPos = Collections.min(positions); maxPos = Collections.max(positions); } NumberRange range; if (startValue != null) { if (endValue == null || endValue < startValue) { endValue = startValue; } range = new NumberRange(startValue, endValue); if (range.containsNumber(minPos) || range.containsNumber(maxPos)) { overlap = true; } } if (minPos != null && maxPos != null) { range = new NumberRange(minPos, maxPos); if (range.containsNumber(startValue) || range.containsNumber(endValue)) { overlap = true; } } return overlap; } }
Numerical { public static boolean overlaps(String input, Integer start, Integer end) { Integer startValue = start; Integer endValue = end; Integer minPos = null; Integer maxPos = null; boolean overlap = false; List<Integer> positions = extractPositiveIntegers(input); if (positions.size() > 0) { minPos = Collections.min(positions); maxPos = Collections.max(positions); } NumberRange range; if (startValue != null) { if (endValue == null || endValue < startValue) { endValue = startValue; } range = new NumberRange(startValue, endValue); if (range.containsNumber(minPos) || range.containsNumber(maxPos)) { overlap = true; } } if (minPos != null && maxPos != null) { range = new NumberRange(minPos, maxPos); if (range.containsNumber(startValue) || range.containsNumber(endValue)) { overlap = true; } } return overlap; }  }
Numerical { public static boolean overlaps(String input, Integer start, Integer end) { Integer startValue = start; Integer endValue = end; Integer minPos = null; Integer maxPos = null; boolean overlap = false; List<Integer> positions = extractPositiveIntegers(input); if (positions.size() > 0) { minPos = Collections.min(positions); maxPos = Collections.max(positions); } NumberRange range; if (startValue != null) { if (endValue == null || endValue < startValue) { endValue = startValue; } range = new NumberRange(startValue, endValue); if (range.containsNumber(minPos) || range.containsNumber(maxPos)) { overlap = true; } } if (minPos != null && maxPos != null) { range = new NumberRange(minPos, maxPos); if (range.containsNumber(startValue) || range.containsNumber(endValue)) { overlap = true; } } return overlap; }  static List<Integer> extractPositiveIntegers(String input); static boolean overlaps(String input, Integer start, Integer end); }
Numerical { public static boolean overlaps(String input, Integer start, Integer end) { Integer startValue = start; Integer endValue = end; Integer minPos = null; Integer maxPos = null; boolean overlap = false; List<Integer> positions = extractPositiveIntegers(input); if (positions.size() > 0) { minPos = Collections.min(positions); maxPos = Collections.max(positions); } NumberRange range; if (startValue != null) { if (endValue == null || endValue < startValue) { endValue = startValue; } range = new NumberRange(startValue, endValue); if (range.containsNumber(minPos) || range.containsNumber(maxPos)) { overlap = true; } } if (minPos != null && maxPos != null) { range = new NumberRange(minPos, maxPos); if (range.containsNumber(startValue) || range.containsNumber(endValue)) { overlap = true; } } return overlap; }  static List<Integer> extractPositiveIntegers(String input); static boolean overlaps(String input, Integer start, Integer end);  }