Last active
August 4, 2016 23:48
-
-
Save stevenschlansker/1a85215249708e325e0baa42e9d7d8bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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