@Test public void testCacheNoDuplicates() { assertNotSame(Namespace.ACCUMULO.id(), Namespace.DEFAULT.id()); String namespaceString = "namespace-" + name.getMethodName(); long initialSize = NamespaceId.cache.asMap().entrySet().stream().count(); NamespaceId nsId = NamespaceId.of(namespaceString); assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count()); assertEquals(namespaceString, nsId.canonical()); NamespaceId builtInNamespaceId = NamespaceId.of("+accumulo"); assertSame(Namespace.ACCUMULO.id(), builtInNamespaceId); builtInNamespaceId = NamespaceId.of("+default"); assertSame(Namespace.DEFAULT.id(), builtInNamespaceId); nsId = NamespaceId.of(namespaceString); assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count()); assertEquals(namespaceString, nsId.canonical()); NamespaceId nsId2 = NamespaceId.of(namespaceString); assertEquals(initialSize + 1, NamespaceId.cache.asMap().entrySet().stream().count()); assertSame(nsId, nsId2); }
public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); static NamespaceId of(final String canonical); }
NamespaceId extends AbstractId<NamespaceId> { public static NamespaceId of(final String canonical) { try { return cache.get(canonical, () -> new NamespaceId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  NamespaceId(String canonical); static NamespaceId of(final String canonical);  }