CodePoints implements Serializable { public int firstExcludedCodePoint(String s) { if (s == null || s.isEmpty()) { return NOT_FOUND; } int len = s.length(); int codePoint; for (int i = 0; i < len; i += Character.charCount(codePoint)) { codePoint = s.codePointAt(i); if (!set.contains(codePoint)) { return codePoint; } } return NOT_FOUND; } 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 testGetFirstNotAllowedCodePoint_null() { String testStr = null; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); int result = new CodePoints(allowedCodePointSet).firstExcludedCodePoint( testStr); assertThat(result, is(CodePoints.NOT_FOUND)); }
@Test public void testGetFirstNotAllowedCodePoint_empty() { String testStr = ""; Set<Integer> allowedCodePointSet = new HashSet<Integer>(); int result = new CodePoints(allowedCodePointSet).firstExcludedCodePoint( testStr); assertThat(result, is(CodePoints.NOT_FOUND)); }
@Test public void testGetFirstNotAllowedCodePoint_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); int result = new CodePoints(allowedCodePointSet).firstExcludedCodePoint( testStr); assertThat(result, is(CodePoints.NOT_FOUND)); }
@Test public void testGetFirstNotAllowedCodePoint_includingNotAllowedCodePoint() { 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); int result = new CodePoints(allowedCodePointSet).firstExcludedCodePoint( testStr); assertThat(result, is("か".codePointAt(0))); }