@Test public void testCacheNoDuplicates() { assertNotSame(RootTable.ID, MetadataTable.ID); assertNotSame(RootTable.ID, ReplicationTable.ID); String tableString = "table-" + name.getMethodName(); long initialSize = TableId.cache.asMap().entrySet().stream().count(); TableId table1 = TableId.of(tableString); assertEquals(initialSize + 1, TableId.cache.asMap().entrySet().stream().count()); assertEquals(tableString, table1.canonical()); TableId builtInTableId = TableId.of("!0"); assertSame(MetadataTable.ID, builtInTableId); builtInTableId = TableId.of("+r"); assertSame(RootTable.ID, builtInTableId); builtInTableId = TableId.of("+rep"); assertSame(ReplicationTable.ID, builtInTableId); table1 = TableId.of(tableString); assertEquals(initialSize + 1, TableId.cache.asMap().entrySet().stream().count()); assertEquals(tableString, table1.canonical()); TableId table2 = TableId.of(tableString); assertEquals(initialSize + 1, TableId.cache.asMap().entrySet().stream().count()); assertEquals(tableString, table2.canonical()); assertSame(table1, table2); }
public static TableId of(final String canonical) { try { return cache.get(canonical, () -> new TableId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } }
TableId extends AbstractId<TableId> { public static TableId of(final String canonical) { try { return cache.get(canonical, () -> new TableId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } }
TableId extends AbstractId<TableId> { public static TableId of(final String canonical) { try { return cache.get(canonical, () -> new TableId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  TableId(final String canonical); }
TableId extends AbstractId<TableId> { public static TableId of(final String canonical) { try { return cache.get(canonical, () -> new TableId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  TableId(final String canonical); static TableId of(final String canonical); }
TableId extends AbstractId<TableId> { public static TableId of(final String canonical) { try { return cache.get(canonical, () -> new TableId(canonical)); } catch (ExecutionException e) { throw new AssertionError( "This should never happen: ID constructor should never return null."); } } private  TableId(final String canonical); static TableId of(final String canonical);  }