@Override public boolean putAll(K key, Collection<? extends V> values) { return get(key).addAll(values); }
@Override public int size() { return getMap().size(); }
/** * * @param mapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { checkArgumentNotNull(mapSupplier, "mapSupplier"); checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.map = mapSupplier.get(); if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
/** * * @param mapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { checkArgumentNotNull(mapSupplier, "mapSupplier"); checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.map = mapSupplier.get(); if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
@Override public boolean put(K key, V value) { return get(key).add(value); }
/** * * @param mapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { checkArgumentNotNull(mapSupplier, "mapSupplier"); checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.map = mapSupplier.get(); if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
@Override public boolean containsKey(Object key) { return getMap().containsKey(key); }
@Override public boolean put(K key, V value) { return get(key).add(value); }
/** * * @param mapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { checkArgumentNotNull(mapSupplier, "mapSupplier"); checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.map = mapSupplier.get(); if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
@Override public void clear() { getMap().clear(); }
@Override public boolean putAll(K key, Collection<? extends V> values) { return get(key).addAll(values); }
/** * * @param mapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { checkArgumentNotNull(mapSupplier, "mapSupplier"); checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.map = mapSupplier.get(); if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
@Override public boolean isEmpty() { return getMap().isEmpty(); }
@Override public boolean putAll(K key, Collection<? extends V> values) { return get(key).addAll(values); }
/** Only one map supplier can be provided, otherwise there is an exception * * @param mapSupplier * @param concurrentMapSupplier * @param collectionSupplier * @param multimap */ protected AbstractMultimap(Supplier<Map<K, C>> mapSupplier, Supplier<ConcurrentMap<K, C>> concurrentMapSupplier, Supplier<C> collectionSupplier, Multimap<K, V> multimap) { // exactly one map supplier has to have a non-null value if ((mapSupplier == null && concurrentMapSupplier == null) ||(mapSupplier != null && concurrentMapSupplier != null)) { throw new IllegalArgumentException("AbstractMultimap has to have only one map supplier provided"); } checkArgumentNotNull(collectionSupplier, "collectionSupplier"); this.supplier = collectionSupplier; this.concurrentMap = (concurrentMapSupplier != null) ? concurrentMapSupplier.get() : null; this.map = (mapSupplier != null) ? mapSupplier.get() : null; if (multimap != null) { for (Entry<K, Collection<V>> entry : multimap.entrySet()) { C values = supplier.get(); values.addAll(entry.getValue()); putAll(entry.getKey(), values); } } }
@Override public String toString() { return getMap().toString(); }
@Override public boolean put(K key, V value) { return get(key).add(value); }
@Override public Set<K> keySet() { return ImmutableSet.copyOf(getMap().keySet()); }
@Override public boolean putAll(K key, Collection<? extends V> values) { return get(key).addAll(values); }
@Override public C replaceValues(K key, Iterable<? extends V> values) { C replacement = supplier.get(); Iterables.addAll(replacement, values); return getMap().put(key, replacement); }