@@ -0,0 +1,3156 @@
+package com.pturpin.quickcheck.registry;%0A%0Aimport com.google.common.collect.ImmutableList;%0Aimport com.google.common.collect.ImmutableMap;%0Aimport com.google.common.collect.Streams;%0Aimport com.pturpin.quickcheck.generator.Generator;%0Aimport com.pturpin.quickcheck.identifier.TypeIdentifier;%0A%0Aimport java.util.Map;%0Aimport java.util.Optional;%0A%0Aimport static com.google.common.base.Preconditions.checkArgument;%0Aimport static com.google.common.base.Preconditions.checkNotNull;%0A%0A/**%0A * Created by pturpin on 27/04/2017.%0A */%0Apublic final class Registries %7B%0A%0A    private Registries() %7B /* Helper class */ %7D%0A%0A    private static RegistryBuilder builder() %7B%0A        return new RegistryBuilder();%0A    %7D%0A%0A    private static Registry forMap(Map%3CTypeIdentifier%3C?%3E, Generator%3C?%3E%3E map) %7B%0A        return new MapRegistry(ImmutableMap.copyOf(map));%0A    %7D%0A%0A    private static Registry empty() %7B%0A        return EmptyRegistry.EMPTY_INSTANCE;%0A    %7D%0A%0A    private static Registry alternatives(Iterable%3CRegistry%3E registries) %7B%0A        return new AlternativeRegistry(ImmutableList.copyOf(registries));%0A    %7D%0A%0A    private static Registry alternatives(Registry... registries) %7B%0A        return new AlternativeRegistry(ImmutableList.copyOf(registries));%0A    %7D%0A%0A    private static final class AlternativeRegistry implements Registry %7B%0A        private final ImmutableList%3CRegistry%3E registries;%0A%0A        private AlternativeRegistry(ImmutableList%3CRegistry%3E registries) %7B%0A            checkArgument(registries.size() %3E 1);%0A            this.registries = registries;%0A        %7D%0A%0A        @Override%0A        public %3CT%3E Optional%3CGenerator%3CT%3E%3E lookup(TypeIdentifier%3CT%3E identifier) %7B%0A            return registries.stream()%0A                    .map(registry -%3E registry.lookup(identifier))%0A                    .flatMap(Streams::stream)%0A                    .findFirst();%0A        %7D%0A    %7D%0A%0A    private static final class EmptyRegistry implements Registry %7B%0A        private static final Registry EMPTY_INSTANCE = new EmptyRegistry();%0A%0A        EmptyRegistry() %7B /* nothing */ %7D%0A%0A        @Override%0A        public %3CT%3E Optional%3CGenerator%3CT%3E%3E lookup(TypeIdentifier%3CT%3E identifier) %7B%0A            return Optional.empty();%0A        %7D%0A    %7D%0A%0A    private static final class MapRegistry implements Registry %7B%0A        private final ImmutableMap%3CTypeIdentifier%3C?%3E, Generator%3C?%3E%3E map;%0A%0A        private MapRegistry(ImmutableMap%3CTypeIdentifier%3C?%3E, Generator%3C?%3E%3E map) %7B%0A            this.map = checkNotNull(map);%0A        %7D%0A%0A        @Override%0A        public %3CT%3E Optional%3CGenerator%3CT%3E%3E lookup(TypeIdentifier%3CT%3E identifier) %7B%0A            return Optional.ofNullable((Generator) map.get(identifier));%0A        %7D%0A    %7D%0A%0A    public static final class RegistryBuilder %7B%0A        private final ImmutableMap.Builder%3CTypeIdentifier%3C?%3E, Generator%3C?%3E%3E builder;%0A%0A        private RegistryBuilder() %7B%0A            this.builder = ImmutableMap.builder();%0A        %7D%0A%0A        private %3CT%3E RegistryBuilder put(TypeIdentifier%3CT%3E identifier, Generator%3CT%3E generator) %7B%0A            builder.put(identifier, generator);%0A            return this;%0A        %7D%0A%0A        private Registry build() %7B%0A            return new MapRegistry(builder.build());%0A        %7D%0A    %7D%0A%7D%0A

Add some Registry factories