TextPatternUtil { public static Set<CharPattern> getCharPatterns(List<Integer> codePoints, List<Integer> filteredCodepoints) { Set<CharPattern> charPatternSet = new TreeSet<>(); for (Integer codepoint : codePoints) { CharPattern charPattern = getCharPattern(codepoint); if (charPattern != null) { charPatternSet.add(charPattern); filteredCodepoints.add(codepoint); } } return charPatternSet; } private  TextPatternUtil(); static String findPattern(String stringToRecognize); static Integer replaceCharacter(Integer codePointToReplace, Random random); static List<Integer> replaceStringCodePoints(String stringToReplace, Random random); static char[] replacePatternCharacter(Integer codePointToReplace, Random random); static Set<CharPattern> getCharPatterns(List<Integer> codePoints, List<Integer> filteredCodepoints); static CharPattern getCharPattern(Integer codepoint); static final int PROLONGED_SOUND_MARK; }
@Test public void getPatternLatin() { List<Integer> codepoints = Arrays.asList((int) 'a', (int) 'é', (int) '-', (int) 'A', (int) '€', (int) 'b'); List<Integer> filteredCodepoints = new ArrayList<>(); Set<CharPattern> charPatternSet = TextPatternUtil.getCharPatterns(codepoints, filteredCodepoints); assertTrue(charPatternSet.contains(CharPattern.LOWER_LATIN)); assertTrue(charPatternSet.contains(CharPattern.LOWER_LATIN_RARE)); assertTrue(charPatternSet.contains(CharPattern.UPPER_LATIN)); assertEquals((int) 'a', (int) filteredCodepoints.get(0)); assertEquals((int) 'é', (int) filteredCodepoints.get(1)); assertEquals((int) 'A', (int) filteredCodepoints.get(2)); assertEquals((int) 'b', (int) filteredCodepoints.get(3)); assertEquals(3, charPatternSet.size()); }
@Test public void findPatternSetAlwaysWithSameOrder() { List<Integer> codepoints1 = Arrays.asList((int) 'a', (int) 'b', (int) 'c', (int) '1', (int) '2', (int) '3'); List<Integer> codepoints2 = Arrays.asList((int) '1', (int) '2', (int) '3', (int) 'a', (int) 'b', (int) 'c'); Set<CharPattern> set1 = TextPatternUtil.getCharPatterns(codepoints1, new ArrayList<>()); Set<CharPattern> set2 = TextPatternUtil.getCharPatterns(codepoints2, new ArrayList<>()); List<CharPattern> list1 = new ArrayList<>(set1); List<CharPattern> list2 = new ArrayList<>(set2); assertTrue(set1 instanceof SortedSet); assertEquals(list1, list2); }