Skip to content

Instantly share code, notes, and snippets.

@stevenschlansker
Last active August 4, 2016 23:48
Show Gist options
  • Save stevenschlansker/1a85215249708e325e0baa42e9d7d8bb to your computer and use it in GitHub Desktop.
Save stevenschlansker/1a85215249708e325e0baa42e9d7d8bb to your computer and use it in GitHub Desktop.
interface Config<C extends Config<C>> {
C createCopy();
}
interface Factory<C extends Config<C>> {
}
class Registry {
private static class Entry<C extends Config<C>> {
static <C extends Config<C>> Entry<C> copyOf(Entry<C> entry) {
return new Entry<>(entry.factory, entry.config.createCopy());
}
final Factory<C> factory;
final C config;
Entry(Factory<C> factory, C config) {
this.factory = factory;
this.config = config;
}
}
private final List<Entry<? extends Config<?>>> entries;
Registry() {
this.entries = new CopyOnWriteArrayList<>();
}
Registry(List<Entry<? extends Config<?>>> entries) {
this.entries = entries.stream()
.map(Entry::copyOf) // The type ExtensionRegistry.Entry does not define copyOf(ExtensionRegistry.Entry<capture#1-of ? extends ExtensionConfig<?>>) that is applicable here
.collect(toCollection(CopyOnWriteArrayList::new));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment