Numerical { public static List<Integer> extractPositiveIntegers(String input) { if (input == null) { return Collections.emptyList(); } List<Integer> list = new ArrayList<>(); Pattern p = Pattern.compile("\\d+"); Matcher m = p.matcher(input); while (m.find()) { list.add(Integer.parseInt(m.group())); } return list; }  static List<Integer> extractPositiveIntegers(String input); static boolean overlaps(String input, Integer start, Integer end);  }
@Test public void positiveIntegerExtractor() { List<Integer> result; Iterator<Integer> iterator; result = Numerical.extractPositiveIntegers(null); assertEquals(0, result.size()); result = Numerical.extractPositiveIntegers("I have no integers!"); assertEquals(0, result.size()); result = Numerical.extractPositiveIntegers("V600"); iterator = result.iterator(); assertEquals(1, result.size()); assertEquals((Integer)600, iterator.next()); result = Numerical.extractPositiveIntegers("666-668"); iterator = result.iterator(); assertEquals(2, result.size()); assertEquals((Integer)666, iterator.next()); assertEquals((Integer)668, iterator.next()); }