001/*
002 * Copyright (C) 2008 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package com.google.common.collect;
018
019import static com.google.common.base.Preconditions.checkNotNull;
020import static com.google.common.collect.CollectPreconditions.checkEntryNotNull;
021
022import com.google.common.annotations.Beta;
023import com.google.common.annotations.GwtCompatible;
024import com.google.common.annotations.GwtIncompatible;
025import com.google.errorprone.annotations.CanIgnoreReturnValue;
026import com.google.errorprone.annotations.DoNotMock;
027import com.google.j2objc.annotations.Weak;
028import com.google.j2objc.annotations.WeakOuter;
029import java.io.Serializable;
030import java.util.ArrayList;
031import java.util.Arrays;
032import java.util.Collection;
033import java.util.Comparator;
034import java.util.Iterator;
035import java.util.Map;
036import java.util.Map.Entry;
037import java.util.Set;
038import java.util.Spliterator;
039import java.util.function.BiConsumer;
040import org.checkerframework.checker.nullness.qual.Nullable;
041
042/**
043 * A {@link Multimap} whose contents will never change, with many other important properties
044 * detailed at {@link ImmutableCollection}.
045 *
046 * <p><b>Warning:</b> avoid <i>direct</i> usage of {@link ImmutableMultimap} as a type (as with
047 * {@link Multimap} itself). Prefer subtypes such as {@link ImmutableSetMultimap} or {@link
048 * ImmutableListMultimap}, which have well-defined {@link #equals} semantics, thus avoiding a common
049 * source of bugs and confusion.
050 *
051 * <p><b>Note:</b> every {@link ImmutableMultimap} offers an {@link #inverse} view, so there is no
052 * need for a distinct {@code ImmutableBiMultimap} type.
053 *
054 * <p><a id="iteration"></a>
055 *
056 * <p><b>Key-grouped iteration.</b> All view collections follow the same iteration order. In all
057 * current implementations, the iteration order always keeps multiple entries with the same key
058 * together. Any creation method that would customarily respect insertion order (such as {@link
059 * #copyOf(Multimap)}) instead preserves key-grouped order by inserting entries for an existing key
060 * immediately after the last entry having that key.
061 *
062 * <p>See the Guava User Guide article on <a href=
063 * "https://github.com/google/guava/wiki/ImmutableCollectionsExplained"> immutable collections</a>.
064 *
065 * @author Jared Levy
066 * @since 2.0
067 */
068@GwtCompatible(emulated = true)
069public abstract class ImmutableMultimap<K, V> extends BaseImmutableMultimap<K, V>
070    implements Serializable {
071
072  /** Returns an empty multimap. */
073  public static <K, V> ImmutableMultimap<K, V> of() {
074    return ImmutableListMultimap.of();
075  }
076
077  /** Returns an immutable multimap containing a single entry. */
078  public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1) {
079    return ImmutableListMultimap.of(k1, v1);
080  }
081
082  /** Returns an immutable multimap containing the given entries, in order. */
083  public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2) {
084    return ImmutableListMultimap.of(k1, v1, k2, v2);
085  }
086
087  /**
088   * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion
089   * order described in the <a href="#iteration">class documentation</a>.
090   */
091  public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
092    return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3);
093  }
094
095  /**
096   * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion
097   * order described in the <a href="#iteration">class documentation</a>.
098   */
099  public static <K, V> ImmutableMultimap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
100    return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4);
101  }
102
103  /**
104   * Returns an immutable multimap containing the given entries, in the "key-grouped" insertion
105   * order described in the <a href="#iteration">class documentation</a>.
106   */
107  public static <K, V> ImmutableMultimap<K, V> of(
108      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
109    return ImmutableListMultimap.of(k1, v1, k2, v2, k3, v3, k4, v4, k5, v5);
110  }
111
112  // looking for of() with > 5 entries? Use the builder instead.
113
114  /**
115   * Returns a new builder. The generated builder is equivalent to the builder created by the {@link
116   * Builder} constructor.
117   */
118  public static <K, V> Builder<K, V> builder() {
119    return new Builder<>();
120  }
121
122  /**
123   * A builder for creating immutable multimap instances, especially {@code public static final}
124   * multimaps ("constant multimaps"). Example:
125   *
126   * <pre>{@code
127   * static final Multimap<String, Integer> STRING_TO_INTEGER_MULTIMAP =
128   *     new ImmutableMultimap.Builder<String, Integer>()
129   *         .put("one", 1)
130   *         .putAll("several", 1, 2, 3)
131   *         .putAll("many", 1, 2, 3, 4, 5)
132   *         .build();
133   * }</pre>
134   *
135   * <p>Builder instances can be reused; it is safe to call {@link #build} multiple times to build
136   * multiple multimaps in series. Each multimap contains the key-value mappings in the previously
137   * created multimaps.
138   *
139   * @since 2.0
140   */
141  @DoNotMock
142  public static class Builder<K, V> {
143    Map<K, Collection<V>> builderMap;
144    @Nullable Comparator<? super K> keyComparator;
145    @Nullable Comparator<? super V> valueComparator;
146
147    /**
148     * Creates a new builder. The returned builder is equivalent to the builder generated by {@link
149     * ImmutableMultimap#builder}.
150     */
151    public Builder() {
152      this.builderMap = Platform.preservesInsertionOrderOnPutsMap();
153    }
154
155    Collection<V> newMutableValueCollection() {
156      return new ArrayList<>();
157    }
158
159    /** Adds a key-value mapping to the built multimap. */
160    @CanIgnoreReturnValue
161    public Builder<K, V> put(K key, V value) {
162      checkEntryNotNull(key, value);
163      Collection<V> valueCollection = builderMap.get(key);
164      if (valueCollection == null) {
165        builderMap.put(key, valueCollection = newMutableValueCollection());
166      }
167      valueCollection.add(value);
168      return this;
169    }
170
171    /**
172     * Adds an entry to the built multimap.
173     *
174     * @since 11.0
175     */
176    @CanIgnoreReturnValue
177    public Builder<K, V> put(Entry<? extends K, ? extends V> entry) {
178      return put(entry.getKey(), entry.getValue());
179    }
180
181    /**
182     * Adds entries to the built multimap.
183     *
184     * @since 19.0
185     */
186    @CanIgnoreReturnValue
187    @Beta
188    public Builder<K, V> putAll(Iterable<? extends Entry<? extends K, ? extends V>> entries) {
189      for (Entry<? extends K, ? extends V> entry : entries) {
190        put(entry);
191      }
192      return this;
193    }
194
195    /**
196     * Stores a collection of values with the same key in the built multimap.
197     *
198     * @throws NullPointerException if {@code key}, {@code values}, or any element in {@code values}
199     *     is null. The builder is left in an invalid state.
200     */
201    @CanIgnoreReturnValue
202    public Builder<K, V> putAll(K key, Iterable<? extends V> values) {
203      if (key == null) {
204        throw new NullPointerException("null key in entry: null=" + Iterables.toString(values));
205      }
206      Collection<V> valueCollection = builderMap.get(key);
207      if (valueCollection != null) {
208        for (V value : values) {
209          checkEntryNotNull(key, value);
210          valueCollection.add(value);
211        }
212        return this;
213      }
214      Iterator<? extends V> valuesItr = values.iterator();
215      if (!valuesItr.hasNext()) {
216        return this;
217      }
218      valueCollection = newMutableValueCollection();
219      while (valuesItr.hasNext()) {
220        V value = valuesItr.next();
221        checkEntryNotNull(key, value);
222        valueCollection.add(value);
223      }
224      builderMap.put(key, valueCollection);
225      return this;
226    }
227
228    /**
229     * Stores an array of values with the same key in the built multimap.
230     *
231     * @throws NullPointerException if the key or any value is null. The builder is left in an
232     *     invalid state.
233     */
234    @CanIgnoreReturnValue
235    public Builder<K, V> putAll(K key, V... values) {
236      return putAll(key, Arrays.asList(values));
237    }
238
239    /**
240     * Stores another multimap's entries in the built multimap. The generated multimap's key and
241     * value orderings correspond to the iteration ordering of the {@code multimap.asMap()} view,
242     * with new keys and values following any existing keys and values.
243     *
244     * @throws NullPointerException if any key or value in {@code multimap} is null. The builder is
245     *     left in an invalid state.
246     */
247    @CanIgnoreReturnValue
248    public Builder<K, V> putAll(Multimap<? extends K, ? extends V> multimap) {
249      for (Entry<? extends K, ? extends Collection<? extends V>> entry :
250          multimap.asMap().entrySet()) {
251        putAll(entry.getKey(), entry.getValue());
252      }
253      return this;
254    }
255
256    /**
257     * Specifies the ordering of the generated multimap's keys.
258     *
259     * @since 8.0
260     */
261    @CanIgnoreReturnValue
262    public Builder<K, V> orderKeysBy(Comparator<? super K> keyComparator) {
263      this.keyComparator = checkNotNull(keyComparator);
264      return this;
265    }
266
267    /**
268     * Specifies the ordering of the generated multimap's values for each key.
269     *
270     * @since 8.0
271     */
272    @CanIgnoreReturnValue
273    public Builder<K, V> orderValuesBy(Comparator<? super V> valueComparator) {
274      this.valueComparator = checkNotNull(valueComparator);
275      return this;
276    }
277
278    @CanIgnoreReturnValue
279    Builder<K, V> combine(Builder<K, V> other) {
280      for (Map.Entry<K, Collection<V>> entry : other.builderMap.entrySet()) {
281        putAll(entry.getKey(), entry.getValue());
282      }
283      return this;
284    }
285
286    /** Returns a newly-created immutable multimap. */
287    public ImmutableMultimap<K, V> build() {
288      Collection<Map.Entry<K, Collection<V>>> mapEntries = builderMap.entrySet();
289      if (keyComparator != null) {
290        mapEntries = Ordering.from(keyComparator).<K>onKeys().immutableSortedCopy(mapEntries);
291      }
292      return ImmutableListMultimap.fromMapEntries(mapEntries, valueComparator);
293    }
294  }
295
296  /**
297   * Returns an immutable multimap containing the same mappings as {@code multimap}, in the
298   * "key-grouped" iteration order described in the class documentation.
299   *
300   * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
301   * safe to do so. The exact circumstances under which a copy will or will not be performed are
302   * undocumented and subject to change.
303   *
304   * @throws NullPointerException if any key or value in {@code multimap} is null
305   */
306  public static <K, V> ImmutableMultimap<K, V> copyOf(Multimap<? extends K, ? extends V> multimap) {
307    if (multimap instanceof ImmutableMultimap) {
308      @SuppressWarnings("unchecked") // safe since multimap is not writable
309      ImmutableMultimap<K, V> kvMultimap = (ImmutableMultimap<K, V>) multimap;
310      if (!kvMultimap.isPartialView()) {
311        return kvMultimap;
312      }
313    }
314    return ImmutableListMultimap.copyOf(multimap);
315  }
316
317  /**
318   * Returns an immutable multimap containing the specified entries. The returned multimap iterates
319   * over keys in the order they were first encountered in the input, and the values for each key
320   * are iterated in the order they were encountered.
321   *
322   * @throws NullPointerException if any key, value, or entry is null
323   * @since 19.0
324   */
325  @Beta
326  public static <K, V> ImmutableMultimap<K, V> copyOf(
327      Iterable<? extends Entry<? extends K, ? extends V>> entries) {
328    return ImmutableListMultimap.copyOf(entries);
329  }
330
331  final transient ImmutableMap<K, ? extends ImmutableCollection<V>> map;
332  final transient int size;
333
334  // These constants allow the deserialization code to set final fields. This
335  // holder class makes sure they are not initialized unless an instance is
336  // deserialized.
337  @GwtIncompatible // java serialization is not supported
338  static class FieldSettersHolder {
339    static final Serialization.FieldSetter<ImmutableMultimap> MAP_FIELD_SETTER =
340        Serialization.getFieldSetter(ImmutableMultimap.class, "map");
341    static final Serialization.FieldSetter<ImmutableMultimap> SIZE_FIELD_SETTER =
342        Serialization.getFieldSetter(ImmutableMultimap.class, "size");
343  }
344
345  ImmutableMultimap(ImmutableMap<K, ? extends ImmutableCollection<V>> map, int size) {
346    this.map = map;
347    this.size = size;
348  }
349
350  // mutators (not supported)
351
352  /**
353   * Guaranteed to throw an exception and leave the multimap unmodified.
354   *
355   * @throws UnsupportedOperationException always
356   * @deprecated Unsupported operation.
357   */
358  @CanIgnoreReturnValue
359  @Deprecated
360  @Override
361  public ImmutableCollection<V> removeAll(Object key) {
362    throw new UnsupportedOperationException();
363  }
364
365  /**
366   * Guaranteed to throw an exception and leave the multimap unmodified.
367   *
368   * @throws UnsupportedOperationException always
369   * @deprecated Unsupported operation.
370   */
371  @CanIgnoreReturnValue
372  @Deprecated
373  @Override
374  public ImmutableCollection<V> replaceValues(K key, Iterable<? extends V> values) {
375    throw new UnsupportedOperationException();
376  }
377
378  /**
379   * Guaranteed to throw an exception and leave the multimap unmodified.
380   *
381   * @throws UnsupportedOperationException always
382   * @deprecated Unsupported operation.
383   */
384  @Deprecated
385  @Override
386  public void clear() {
387    throw new UnsupportedOperationException();
388  }
389
390  /**
391   * Returns an immutable collection of the values for the given key. If no mappings in the multimap
392   * have the provided key, an empty immutable collection is returned. The values are in the same
393   * order as the parameters used to build this multimap.
394   */
395  @Override
396  public abstract ImmutableCollection<V> get(K key);
397
398  /**
399   * Returns an immutable multimap which is the inverse of this one. For every key-value mapping in
400   * the original, the result will have a mapping with key and value reversed.
401   *
402   * @since 11.0
403   */
404  public abstract ImmutableMultimap<V, K> inverse();
405
406  /**
407   * Guaranteed to throw an exception and leave the multimap unmodified.
408   *
409   * @throws UnsupportedOperationException always
410   * @deprecated Unsupported operation.
411   */
412  @CanIgnoreReturnValue
413  @Deprecated
414  @Override
415  public boolean put(K key, V value) {
416    throw new UnsupportedOperationException();
417  }
418
419  /**
420   * Guaranteed to throw an exception and leave the multimap unmodified.
421   *
422   * @throws UnsupportedOperationException always
423   * @deprecated Unsupported operation.
424   */
425  @CanIgnoreReturnValue
426  @Deprecated
427  @Override
428  public boolean putAll(K key, Iterable<? extends V> values) {
429    throw new UnsupportedOperationException();
430  }
431
432  /**
433   * Guaranteed to throw an exception and leave the multimap unmodified.
434   *
435   * @throws UnsupportedOperationException always
436   * @deprecated Unsupported operation.
437   */
438  @CanIgnoreReturnValue
439  @Deprecated
440  @Override
441  public boolean putAll(Multimap<? extends K, ? extends V> multimap) {
442    throw new UnsupportedOperationException();
443  }
444
445  /**
446   * Guaranteed to throw an exception and leave the multimap unmodified.
447   *
448   * @throws UnsupportedOperationException always
449   * @deprecated Unsupported operation.
450   */
451  @CanIgnoreReturnValue
452  @Deprecated
453  @Override
454  public boolean remove(Object key, Object value) {
455    throw new UnsupportedOperationException();
456  }
457
458  /**
459   * Returns {@code true} if this immutable multimap's implementation contains references to
460   * user-created objects that aren't accessible via this multimap's methods. This is generally used
461   * to determine whether {@code copyOf} implementations should make an explicit copy to avoid
462   * memory leaks.
463   */
464  boolean isPartialView() {
465    return map.isPartialView();
466  }
467
468  // accessors
469
470  @Override
471  public boolean containsKey(@Nullable Object key) {
472    return map.containsKey(key);
473  }
474
475  @Override
476  public boolean containsValue(@Nullable Object value) {
477    return value != null && super.containsValue(value);
478  }
479
480  @Override
481  public int size() {
482    return size;
483  }
484
485  // views
486
487  /**
488   * Returns an immutable set of the distinct keys in this multimap, in the same order as they
489   * appear in this multimap.
490   */
491  @Override
492  public ImmutableSet<K> keySet() {
493    return map.keySet();
494  }
495
496  @Override
497  Set<K> createKeySet() {
498    throw new AssertionError("unreachable");
499  }
500
501  /**
502   * Returns an immutable map that associates each key with its corresponding values in the
503   * multimap. Keys and values appear in the same order as in this multimap.
504   */
505  @Override
506  @SuppressWarnings("unchecked") // a widening cast
507  public ImmutableMap<K, Collection<V>> asMap() {
508    return (ImmutableMap) map;
509  }
510
511  @Override
512  Map<K, Collection<V>> createAsMap() {
513    throw new AssertionError("should never be called");
514  }
515
516  /** Returns an immutable collection of all key-value pairs in the multimap. */
517  @Override
518  public ImmutableCollection<Entry<K, V>> entries() {
519    return (ImmutableCollection<Entry<K, V>>) super.entries();
520  }
521
522  @Override
523  ImmutableCollection<Entry<K, V>> createEntries() {
524    return new EntryCollection<>(this);
525  }
526
527  private static class EntryCollection<K, V> extends ImmutableCollection<Entry<K, V>> {
528    @Weak final ImmutableMultimap<K, V> multimap;
529
530    EntryCollection(ImmutableMultimap<K, V> multimap) {
531      this.multimap = multimap;
532    }
533
534    @Override
535    public UnmodifiableIterator<Entry<K, V>> iterator() {
536      return multimap.entryIterator();
537    }
538
539    @Override
540    boolean isPartialView() {
541      return multimap.isPartialView();
542    }
543
544    @Override
545    public int size() {
546      return multimap.size();
547    }
548
549    @Override
550    public boolean contains(Object object) {
551      if (object instanceof Entry) {
552        Entry<?, ?> entry = (Entry<?, ?>) object;
553        return multimap.containsEntry(entry.getKey(), entry.getValue());
554      }
555      return false;
556    }
557
558    private static final long serialVersionUID = 0;
559  }
560
561  @Override
562  UnmodifiableIterator<Entry<K, V>> entryIterator() {
563    return new UnmodifiableIterator<Entry<K, V>>() {
564      final Iterator<? extends Entry<K, ? extends ImmutableCollection<V>>> asMapItr =
565          map.entrySet().iterator();
566      K currentKey = null;
567      Iterator<V> valueItr = Iterators.emptyIterator();
568
569      @Override
570      public boolean hasNext() {
571        return valueItr.hasNext() || asMapItr.hasNext();
572      }
573
574      @Override
575      public Entry<K, V> next() {
576        if (!valueItr.hasNext()) {
577          Entry<K, ? extends ImmutableCollection<V>> entry = asMapItr.next();
578          currentKey = entry.getKey();
579          valueItr = entry.getValue().iterator();
580        }
581        return Maps.immutableEntry(currentKey, valueItr.next());
582      }
583    };
584  }
585
586  @Override
587  Spliterator<Entry<K, V>> entrySpliterator() {
588    return CollectSpliterators.flatMap(
589        asMap().entrySet().spliterator(),
590        keyToValueCollectionEntry -> {
591          K key = keyToValueCollectionEntry.getKey();
592          Collection<V> valueCollection = keyToValueCollectionEntry.getValue();
593          return CollectSpliterators.map(
594              valueCollection.spliterator(), (V value) -> Maps.immutableEntry(key, value));
595        },
596        Spliterator.SIZED | (this instanceof SetMultimap ? Spliterator.DISTINCT : 0),
597        size());
598  }
599
600  @Override
601  public void forEach(BiConsumer<? super K, ? super V> action) {
602    checkNotNull(action);
603    asMap()
604        .forEach(
605            (key, valueCollection) -> valueCollection.forEach(value -> action.accept(key, value)));
606  }
607
608  /**
609   * Returns an immutable multiset containing all the keys in this multimap, in the same order and
610   * with the same frequencies as they appear in this multimap; to get only a single occurrence of
611   * each key, use {@link #keySet}.
612   */
613  @Override
614  public ImmutableMultiset<K> keys() {
615    return (ImmutableMultiset<K>) super.keys();
616  }
617
618  @Override
619  ImmutableMultiset<K> createKeys() {
620    return new Keys();
621  }
622
623  @SuppressWarnings("serial") // Uses writeReplace, not default serialization
624  @WeakOuter
625  class Keys extends ImmutableMultiset<K> {
626    @Override
627    public boolean contains(@Nullable Object object) {
628      return containsKey(object);
629    }
630
631    @Override
632    public int count(@Nullable Object element) {
633      Collection<V> values = map.get(element);
634      return (values == null) ? 0 : values.size();
635    }
636
637    @Override
638    public ImmutableSet<K> elementSet() {
639      return keySet();
640    }
641
642    @Override
643    public int size() {
644      return ImmutableMultimap.this.size();
645    }
646
647    @Override
648    Multiset.Entry<K> getEntry(int index) {
649      Map.Entry<K, ? extends Collection<V>> entry = map.entrySet().asList().get(index);
650      return Multisets.immutableEntry(entry.getKey(), entry.getValue().size());
651    }
652
653    @Override
654    boolean isPartialView() {
655      return true;
656    }
657
658    @GwtIncompatible
659    @Override
660    Object writeReplace() {
661      return new KeysSerializedForm(ImmutableMultimap.this);
662    }
663  }
664
665  @GwtIncompatible
666  private static final class KeysSerializedForm implements Serializable {
667    final ImmutableMultimap<?, ?> multimap;
668
669    KeysSerializedForm(ImmutableMultimap<?, ?> multimap) {
670      this.multimap = multimap;
671    }
672
673    Object readResolve() {
674      return multimap.keys();
675    }
676  }
677
678  /**
679   * Returns an immutable collection of the values in this multimap. Its iterator traverses the
680   * values for the first key, the values for the second key, and so on.
681   */
682  @Override
683  public ImmutableCollection<V> values() {
684    return (ImmutableCollection<V>) super.values();
685  }
686
687  @Override
688  ImmutableCollection<V> createValues() {
689    return new Values<>(this);
690  }
691
692  @Override
693  UnmodifiableIterator<V> valueIterator() {
694    return new UnmodifiableIterator<V>() {
695      Iterator<? extends ImmutableCollection<V>> valueCollectionItr = map.values().iterator();
696      Iterator<V> valueItr = Iterators.emptyIterator();
697
698      @Override
699      public boolean hasNext() {
700        return valueItr.hasNext() || valueCollectionItr.hasNext();
701      }
702
703      @Override
704      public V next() {
705        if (!valueItr.hasNext()) {
706          valueItr = valueCollectionItr.next().iterator();
707        }
708        return valueItr.next();
709      }
710    };
711  }
712
713  private static final class Values<K, V> extends ImmutableCollection<V> {
714    @Weak private final transient ImmutableMultimap<K, V> multimap;
715
716    Values(ImmutableMultimap<K, V> multimap) {
717      this.multimap = multimap;
718    }
719
720    @Override
721    public boolean contains(@Nullable Object object) {
722      return multimap.containsValue(object);
723    }
724
725    @Override
726    public UnmodifiableIterator<V> iterator() {
727      return multimap.valueIterator();
728    }
729
730    @GwtIncompatible // not present in emulated superclass
731    @Override
732    int copyIntoArray(Object[] dst, int offset) {
733      for (ImmutableCollection<V> valueCollection : multimap.map.values()) {
734        offset = valueCollection.copyIntoArray(dst, offset);
735      }
736      return offset;
737    }
738
739    @Override
740    public int size() {
741      return multimap.size();
742    }
743
744    @Override
745    boolean isPartialView() {
746      return true;
747    }
748
749    private static final long serialVersionUID = 0;
750  }
751
752  private static final long serialVersionUID = 0;
753}