NumberHelper { public static List<NumberToken> tokenize(String str) { List<NumberToken> result = new ArrayList<>(); Matcher matcher = extractRegex.matcher(str); while (matcher.find()) { String g1 = matcher.group(1); String g2 = matcher.group(2); if (g1 != null) { result.add(new NumberToken(g1, NumberTokenType.NUMBER)); } else if (g2 != null) { result.add(new NumberToken(g2, NumberTokenType.SEPARATOR)); } } return result; }  static boolean isNumeric(String str); static List<NumberToken> tokenize(String str);  }
@Test public void tokenize() { assertEquals(Collections.singletonList(new NumberToken("1", NumberTokenType.NUMBER)), NumberHelper.tokenize("1")); assertEquals(Arrays.asList( new NumberToken("1", NumberTokenType.NUMBER), new NumberToken("-", NumberTokenType.SEPARATOR), new NumberToken("10", NumberTokenType.NUMBER), new NumberToken(",", NumberTokenType.SEPARATOR), new NumberToken("2", NumberTokenType.NUMBER), new NumberToken("-", NumberTokenType.SEPARATOR), new NumberToken("100", NumberTokenType.NUMBER)), NumberHelper.tokenize("1-10,2-100")); assertEquals(Arrays.asList( new NumberToken("42a", NumberTokenType.NUMBER), new NumberToken("-", NumberTokenType.SEPARATOR), new NumberToken("tt0815", NumberTokenType.NUMBER), new NumberToken(",", NumberTokenType.SEPARATOR), new NumberToken("ll47uu", NumberTokenType.NUMBER), new NumberToken("&", NumberTokenType.SEPARATOR), new NumberToken("o11", NumberTokenType.NUMBER)), NumberHelper.tokenize("42a - tt0815 , ll47uu &o11")); }