A Factory implementation used to implement Map bindings. This factory returns a Map > when calling #get (as specified by Factory).
| 30 | * {@code Map<K, Provider<V>>} when calling {@link #get} (as specified by {@link Factory}). |
| 31 | */ |
| 32 | public final class MapProviderFactory<K, V> |
| 33 | implements Factory<Map<K, Provider<V>>>, Lazy<Map<K, Provider<V>>> { |
| 34 | private final Map<K, Provider<V>> contributingMap; |
| 35 | |
| 36 | /** |
| 37 | * Returns a new {@link Builder} |
| 38 | */ |
| 39 | public static <K, V> Builder<K, V> builder(int size) { |
| 40 | return new Builder<>(size); |
| 41 | } |
| 42 | |
| 43 | private MapProviderFactory(Map<K, Provider<V>> contributingMap) { |
| 44 | this.contributingMap = unmodifiableMap(contributingMap); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns a {@code Map<K, Provider<V>>} whose iteration order is that of the elements |
| 49 | * given by each of the providers, which are invoked in the order given at creation. |
| 50 | * |
| 51 | */ |
| 52 | @Override |
| 53 | public Map<K, Provider<V>> get() { |
| 54 | return this.contributingMap; |
| 55 | } |
| 56 | |
| 57 | /** A builder for {@link MapProviderFactory}. */ |
| 58 | public static final class Builder<K, V> { |
| 59 | private final LinkedHashMap<K, Provider<V>> map; |
| 60 | |
| 61 | private Builder(int size) { |
| 62 | this.map = newLinkedHashMapWithExpectedSize(size); |
| 63 | } |
| 64 | |
| 65 | /** Associates {@code key} with {@code providerOfValue}. */ |
| 66 | public Builder<K, V> put(K key, Provider<V> providerOfValue) { |
| 67 | map.put(checkNotNull(key, "key"), checkNotNull(providerOfValue, "provider")); |
| 68 | return this; |
| 69 | } |
| 70 | |
| 71 | /** Returns a new {@link MapProviderFactory}. */ |
| 72 | public MapProviderFactory<K, V> build() { |
| 73 | return new MapProviderFactory<>(map); |
| 74 | } |
| 75 | } |
| 76 | } |
nothing calls this directly
no outgoing calls
no test coverage detected