CodePoints implements Serializable { public Set<Integer> allExcludedCodePoints(String s) { if (s == null || s.isEmpty()) { return Collections.emptySet(); } Set<Integer> excludedCodePoints = new LinkedHashSet<Integer>(); int len = s.length(); Integer codePoint; for (int i = 0; i < len; i += Character.charCount(codePoint)) { codePoint = s.codePointAt(i); if (!set.contains(codePoint)) { excludedCodePoints.add(codePoint); } } return excludedCodePoints; } CodePoints(Integer... codePoints);  CodePoints(String... strings);  CodePoints(Collection<Integer> codePoints);  CodePoints(CodePoints codePoints); boolean containsAll(String s); int firstExcludedCodePoint(String s); Set<Integer> allExcludedCodePoints(String s); CodePoints union(CodePoints codePoints); CodePoints subtract(CodePoints codePoints); CodePoints intersect(CodePoints codePoints); @SuppressWarnings("unchecked") static T of(Class<T> clazz); static boolean containsAllInAnyCodePoints(String s,
            final CodePoints... codePointsList); @Override boolean equals(Object o); @Override int hashCode(); static final int NOT_FOUND; }
@Test public void testGetAllNotAllowedCodePoint_null() { String testStr = null; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); Set<Integer> result = new CodePoints(allowedCodePointSet) .allExcludedCodePoints(testStr); assertThat(result.size(), is(0)); }
@Test public void testGetAllNotAllowedCodePoint_empty() { String testStr = ""; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); Set<Integer> result = new CodePoints(allowedCodePointSet) .allExcludedCodePoints(testStr); assertThat(result.size(), is(0)); }
@Test public void testGetAllNotAllowedCodePoint_allAllowedCodePoints() { String testStr = SURROGATE_PAIR_CHAR_2000B + "あいうあ" + SURROGATE_PAIR_CHAR_2000B; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); allowedCodePointSet.add("あ".codePointAt(0)); allowedCodePointSet.add("い".codePointAt(0)); allowedCodePointSet.add("う".codePointAt(0)); allowedCodePointSet.add("え".codePointAt(0)); allowedCodePointSet.add("お".codePointAt(0)); allowedCodePointSet.add(0x2000B); Set<Integer> result = new CodePoints(allowedCodePointSet) .allExcludedCodePoints(testStr); assertThat(result.size(), is(0)); }
@Test public void testGetAllNotAllowedCodePoint_includingNotAllowedCodePoint() { String testStr = SURROGATE_PAIR_CHAR_2000B + "あいうか"; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); allowedCodePointSet.add("あ".codePointAt(0)); allowedCodePointSet.add("い".codePointAt(0)); allowedCodePointSet.add("う".codePointAt(0)); allowedCodePointSet.add("え".codePointAt(0)); allowedCodePointSet.add("お".codePointAt(0)); allowedCodePointSet.add(0x2000B); Set<Integer> result = new CodePoints(allowedCodePointSet) .allExcludedCodePoints(testStr); assertThat(result.size(), is(1)); assertThat(result.contains("か".codePointAt(0)), is(true)); }