CodePoints implements Serializable { @SuppressWarnings("unchecked") public static <T extends CodePoints> T of(Class<T> clazz) { if (cache.containsKey(clazz)) { return (T) cache.get(clazz); } try { T codePoints = clazz.getDeclaredConstructor().newInstance(); cache.put(clazz, codePoints); return codePoints; } catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException e) { throw new IllegalArgumentException("public default constructor not found", e); } catch (InstantiationException | InvocationTargetException e) { throw new IllegalArgumentException("exception occurred while initializing", e); } } 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 testOf_caches_are_same_instance() { ABCD cp1 = CodePoints.of(ABCD.class); ABCD cp2 = CodePoints.of(ABCD.class); assertThat(cp1, is(sameInstance(cp2))); }
@Test public void testOf_illegal_access() throws Exception { Exception ex = assertThrows(IllegalArgumentException.class, () -> CodePoints.of(IllegalCodePoints.class)); assertThat(ex.getMessage(), is("public default constructor not found")); }
@Test public void testOf_instantiation_fail() { Exception ex = assertThrows(IllegalArgumentException.class, () -> CodePoints.of(AbstractCodePoints.class)); assertThat(ex.getMessage(), is( "exception occurred while initializing")); }