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.collect.CollectPreconditions.checkEntryNotNull;
020import static com.google.common.collect.CollectPreconditions.checkNonnegative;
021
022import com.google.common.annotations.GwtCompatible;
023import com.google.common.annotations.J2ktIncompatible;
024import com.google.errorprone.annotations.CanIgnoreReturnValue;
025import com.google.errorprone.annotations.DoNotCall;
026import java.io.InvalidObjectException;
027import java.io.ObjectInputStream;
028import java.util.Arrays;
029import java.util.Collection;
030import java.util.Comparator;
031import java.util.Map;
032import java.util.function.BinaryOperator;
033import java.util.function.Function;
034import java.util.stream.Collector;
035import java.util.stream.Collectors;
036import org.jspecify.annotations.Nullable;
037
038/**
039 * A {@link BiMap} whose contents will never change, with many other important properties detailed
040 * at {@link ImmutableCollection}.
041 *
042 * @author Jared Levy
043 * @since 2.0
044 */
045@GwtCompatible(serializable = true, emulated = true)
046public abstract class ImmutableBiMap<K, V> extends ImmutableMap<K, V> implements BiMap<K, V> {
047
048  /**
049   * Returns a {@link Collector} that accumulates elements into an {@code ImmutableBiMap} whose keys
050   * and values are the result of applying the provided mapping functions to the input elements.
051   * Entries appear in the result {@code ImmutableBiMap} in encounter order.
052   *
053   * <p>If the mapped keys or values contain duplicates (according to {@link
054   * Object#equals(Object)}), an {@code IllegalArgumentException} is thrown when the collection
055   * operation is performed. (This differs from the {@code Collector} returned by {@link
056   * Collectors#toMap(Function, Function)}, which throws an {@code IllegalStateException}.)
057   *
058   * @since 33.2.0 (available since 21.0 in guava-jre)
059   */
060  @SuppressWarnings("Java7ApiChecker")
061  @IgnoreJRERequirement // Users will use this only if they're already using streams.
062  public static <T extends @Nullable Object, K, V>
063      Collector<T, ?, ImmutableBiMap<K, V>> toImmutableBiMap(
064          Function<? super T, ? extends K> keyFunction,
065          Function<? super T, ? extends V> valueFunction) {
066    return CollectCollectors.toImmutableBiMap(keyFunction, valueFunction);
067  }
068
069  /**
070   * Returns the empty bimap.
071   *
072   * <p><b>Performance note:</b> the instance returned is a singleton.
073   */
074  // Casting to any type is safe because the set will never hold any elements.
075  @SuppressWarnings("unchecked")
076  public static <K, V> ImmutableBiMap<K, V> of() {
077    return (ImmutableBiMap<K, V>) RegularImmutableBiMap.EMPTY;
078  }
079
080  /** Returns an immutable bimap containing a single entry. */
081  public static <K, V> ImmutableBiMap<K, V> of(K k1, V v1) {
082    checkEntryNotNull(k1, v1);
083    return new RegularImmutableBiMap<>(new Object[] {k1, v1}, 1);
084  }
085
086  /**
087   * Returns an immutable map containing the given entries, in order.
088   *
089   * @throws IllegalArgumentException if duplicate keys or values are added
090   */
091  public static <K, V> ImmutableBiMap<K, V> of(K k1, V v1, K k2, V v2) {
092    checkEntryNotNull(k1, v1);
093    checkEntryNotNull(k2, v2);
094    return new RegularImmutableBiMap<K, V>(new Object[] {k1, v1, k2, v2}, 2);
095  }
096
097  /**
098   * Returns an immutable map containing the given entries, in order.
099   *
100   * @throws IllegalArgumentException if duplicate keys or values are added
101   */
102  public static <K, V> ImmutableBiMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
103    checkEntryNotNull(k1, v1);
104    checkEntryNotNull(k2, v2);
105    checkEntryNotNull(k3, v3);
106    return new RegularImmutableBiMap<K, V>(new Object[] {k1, v1, k2, v2, k3, v3}, 3);
107  }
108
109  /**
110   * Returns an immutable map containing the given entries, in order.
111   *
112   * @throws IllegalArgumentException if duplicate keys or values are added
113   */
114  public static <K, V> ImmutableBiMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
115    checkEntryNotNull(k1, v1);
116    checkEntryNotNull(k2, v2);
117    checkEntryNotNull(k3, v3);
118    checkEntryNotNull(k4, v4);
119    return new RegularImmutableBiMap<K, V>(new Object[] {k1, v1, k2, v2, k3, v3, k4, v4}, 4);
120  }
121
122  /**
123   * Returns an immutable map containing the given entries, in order.
124   *
125   * @throws IllegalArgumentException if duplicate keys or values are added
126   */
127  public static <K, V> ImmutableBiMap<K, V> of(
128      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
129    checkEntryNotNull(k1, v1);
130    checkEntryNotNull(k2, v2);
131    checkEntryNotNull(k3, v3);
132    checkEntryNotNull(k4, v4);
133    checkEntryNotNull(k5, v5);
134    return new RegularImmutableBiMap<K, V>(
135        new Object[] {k1, v1, k2, v2, k3, v3, k4, v4, k5, v5}, 5);
136  }
137
138  /**
139   * Returns an immutable map containing the given entries, in order.
140   *
141   * @throws IllegalArgumentException if duplicate keys or values are added
142   * @since 31.0
143   */
144  public static <K, V> ImmutableBiMap<K, V> of(
145      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6) {
146    checkEntryNotNull(k1, v1);
147    checkEntryNotNull(k2, v2);
148    checkEntryNotNull(k3, v3);
149    checkEntryNotNull(k4, v4);
150    checkEntryNotNull(k5, v5);
151    checkEntryNotNull(k6, v6);
152    return new RegularImmutableBiMap<K, V>(
153        new Object[] {k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6}, 6);
154  }
155
156  /**
157   * Returns an immutable map containing the given entries, in order.
158   *
159   * @throws IllegalArgumentException if duplicate keys or values are added
160   * @since 31.0
161   */
162  public static <K, V> ImmutableBiMap<K, V> of(
163      K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5, K k6, V v6, K k7, V v7) {
164    checkEntryNotNull(k1, v1);
165    checkEntryNotNull(k2, v2);
166    checkEntryNotNull(k3, v3);
167    checkEntryNotNull(k4, v4);
168    checkEntryNotNull(k5, v5);
169    checkEntryNotNull(k6, v6);
170    checkEntryNotNull(k7, v7);
171    return new RegularImmutableBiMap<K, V>(
172        new Object[] {k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7}, 7);
173  }
174
175  /**
176   * Returns an immutable map containing the given entries, in order.
177   *
178   * @throws IllegalArgumentException if duplicate keys or values are added
179   * @since 31.0
180   */
181  public static <K, V> ImmutableBiMap<K, V> of(
182      K k1,
183      V v1,
184      K k2,
185      V v2,
186      K k3,
187      V v3,
188      K k4,
189      V v4,
190      K k5,
191      V v5,
192      K k6,
193      V v6,
194      K k7,
195      V v7,
196      K k8,
197      V v8) {
198    checkEntryNotNull(k1, v1);
199    checkEntryNotNull(k2, v2);
200    checkEntryNotNull(k3, v3);
201    checkEntryNotNull(k4, v4);
202    checkEntryNotNull(k5, v5);
203    checkEntryNotNull(k6, v6);
204    checkEntryNotNull(k7, v7);
205    checkEntryNotNull(k8, v8);
206    return new RegularImmutableBiMap<K, V>(
207        new Object[] {k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8}, 8);
208  }
209
210  /**
211   * Returns an immutable map containing the given entries, in order.
212   *
213   * @throws IllegalArgumentException if duplicate keys or values are added
214   * @since 31.0
215   */
216  public static <K, V> ImmutableBiMap<K, V> of(
217      K k1,
218      V v1,
219      K k2,
220      V v2,
221      K k3,
222      V v3,
223      K k4,
224      V v4,
225      K k5,
226      V v5,
227      K k6,
228      V v6,
229      K k7,
230      V v7,
231      K k8,
232      V v8,
233      K k9,
234      V v9) {
235    checkEntryNotNull(k1, v1);
236    checkEntryNotNull(k2, v2);
237    checkEntryNotNull(k3, v3);
238    checkEntryNotNull(k4, v4);
239    checkEntryNotNull(k5, v5);
240    checkEntryNotNull(k6, v6);
241    checkEntryNotNull(k7, v7);
242    checkEntryNotNull(k8, v8);
243    checkEntryNotNull(k9, v9);
244    return new RegularImmutableBiMap<K, V>(
245        new Object[] {k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9}, 9);
246  }
247
248  /**
249   * Returns an immutable map containing the given entries, in order.
250   *
251   * @throws IllegalArgumentException if duplicate keys or values are added
252   * @since 31.0
253   */
254  public static <K, V> ImmutableBiMap<K, V> of(
255      K k1,
256      V v1,
257      K k2,
258      V v2,
259      K k3,
260      V v3,
261      K k4,
262      V v4,
263      K k5,
264      V v5,
265      K k6,
266      V v6,
267      K k7,
268      V v7,
269      K k8,
270      V v8,
271      K k9,
272      V v9,
273      K k10,
274      V v10) {
275    checkEntryNotNull(k1, v1);
276    checkEntryNotNull(k2, v2);
277    checkEntryNotNull(k3, v3);
278    checkEntryNotNull(k4, v4);
279    checkEntryNotNull(k5, v5);
280    checkEntryNotNull(k6, v6);
281    checkEntryNotNull(k7, v7);
282    checkEntryNotNull(k8, v8);
283    checkEntryNotNull(k9, v9);
284    checkEntryNotNull(k10, v10);
285    return new RegularImmutableBiMap<K, V>(
286        new Object[] {
287          k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6, k7, v7, k8, v8, k9, v9, k10, v10
288        },
289        10);
290  }
291
292  // looking for of() with > 10 entries? Use the builder or ofEntries instead.
293
294  /**
295   * Returns an immutable map containing the given entries, in order.
296   *
297   * @throws IllegalArgumentException if duplicate keys or values are provided
298   * @since 31.0
299   */
300  @SafeVarargs
301  public static <K, V> ImmutableBiMap<K, V> ofEntries(Entry<? extends K, ? extends V>... entries) {
302    @SuppressWarnings("unchecked") // we will only ever read these
303    Entry<K, V>[] entries2 = (Entry<K, V>[]) entries;
304    return copyOf(Arrays.asList(entries2));
305  }
306
307  /**
308   * Returns a new builder. The generated builder is equivalent to the builder created by the {@link
309   * Builder} constructor.
310   */
311  public static <K, V> Builder<K, V> builder() {
312    return new Builder<>();
313  }
314
315  /**
316   * Returns a new builder, expecting the specified number of entries to be added.
317   *
318   * <p>If {@code expectedSize} is exactly the number of entries added to the builder before {@link
319   * Builder#build} is called, the builder is likely to perform better than an unsized {@link
320   * #builder()} would have.
321   *
322   * <p>It is not specified if any performance benefits apply if {@code expectedSize} is close to,
323   * but not exactly, the number of entries added to the builder.
324   *
325   * @since 23.1
326   */
327  public static <K, V> Builder<K, V> builderWithExpectedSize(int expectedSize) {
328    checkNonnegative(expectedSize, "expectedSize");
329    return new Builder<>(expectedSize);
330  }
331
332  /**
333   * A builder for creating immutable bimap instances, especially {@code public static final} bimaps
334   * ("constant bimaps"). Example:
335   *
336   * <pre>{@code
337   * static final ImmutableBiMap<String, Integer> WORD_TO_INT =
338   *     new ImmutableBiMap.Builder<String, Integer>()
339   *         .put("one", 1)
340   *         .put("two", 2)
341   *         .put("three", 3)
342   *         .buildOrThrow();
343   * }</pre>
344   *
345   * <p>For <i>small</i> immutable bimaps, the {@code ImmutableBiMap.of()} methods are even more
346   * convenient.
347   *
348   * <p>By default, a {@code Builder} will generate bimaps that iterate over entries in the order
349   * they were inserted into the builder. For example, in the above example, {@code
350   * WORD_TO_INT.entrySet()} is guaranteed to iterate over the entries in the order {@code "one"=1,
351   * "two"=2, "three"=3}, and {@code keySet()} and {@code values()} respect the same order. If you
352   * want a different order, consider using {@link #orderEntriesByValue(Comparator)}, which changes
353   * this builder to sort entries by value.
354   *
355   * <p>Builder instances can be reused - it is safe to call {@link #buildOrThrow} multiple times to
356   * build multiple bimaps in series. Each bimap is a superset of the bimaps created before it.
357   *
358   * @since 2.0
359   */
360  public static final class Builder<K, V> extends ImmutableMap.Builder<K, V> {
361    /**
362     * Creates a new builder. The returned builder is equivalent to the builder generated by {@link
363     * ImmutableBiMap#builder}.
364     */
365    public Builder() {
366      super();
367    }
368
369    Builder(int size) {
370      super(size);
371    }
372
373    /**
374     * Associates {@code key} with {@code value} in the built bimap. Duplicate keys or values are
375     * not allowed, and will cause {@link #build} to fail.
376     */
377    @CanIgnoreReturnValue
378    @Override
379    public Builder<K, V> put(K key, V value) {
380      super.put(key, value);
381      return this;
382    }
383
384    /**
385     * Adds the given {@code entry} to the bimap. Duplicate keys or values are not allowed, and will
386     * cause {@link #build} to fail.
387     *
388     * @since 19.0
389     */
390    @CanIgnoreReturnValue
391    @Override
392    public Builder<K, V> put(Entry<? extends K, ? extends V> entry) {
393      super.put(entry);
394      return this;
395    }
396
397    /**
398     * Associates all of the given map's keys and values in the built bimap. Duplicate keys or
399     * values are not allowed, and will cause {@link #build} to fail.
400     *
401     * @throws NullPointerException if any key or value in {@code map} is null
402     */
403    @CanIgnoreReturnValue
404    @Override
405    public Builder<K, V> putAll(Map<? extends K, ? extends V> map) {
406      super.putAll(map);
407      return this;
408    }
409
410    /**
411     * Adds all of the given entries to the built bimap. Duplicate keys or values are not allowed,
412     * and will cause {@link #build} to fail.
413     *
414     * @throws NullPointerException if any key, value, or entry is null
415     * @since 19.0
416     */
417    @CanIgnoreReturnValue
418    @Override
419    public Builder<K, V> putAll(Iterable<? extends Entry<? extends K, ? extends V>> entries) {
420      super.putAll(entries);
421      return this;
422    }
423
424    /**
425     * Configures this {@code Builder} to order entries by value according to the specified
426     * comparator.
427     *
428     * <p>The sort order is stable, that is, if two entries have values that compare as equivalent,
429     * the entry that was inserted first will be first in the built map's iteration order.
430     *
431     * @throws IllegalStateException if this method was already called
432     * @since 19.0
433     */
434    @CanIgnoreReturnValue
435    @Override
436    public Builder<K, V> orderEntriesByValue(Comparator<? super V> valueComparator) {
437      super.orderEntriesByValue(valueComparator);
438      return this;
439    }
440
441    @Override
442    @CanIgnoreReturnValue
443    Builder<K, V> combine(ImmutableMap.Builder<K, V> builder) {
444      super.combine(builder);
445      return this;
446    }
447
448    /**
449     * Returns a newly-created immutable bimap. The iteration order of the returned bimap is the
450     * order in which entries were inserted into the builder, unless {@link #orderEntriesByValue}
451     * was called, in which case entries are sorted by value.
452     *
453     * <p>Prefer the equivalent method {@link #buildOrThrow()} to make it explicit that the method
454     * will throw an exception if there are duplicate keys or values. The {@code build()} method
455     * will soon be deprecated.
456     *
457     * @throws IllegalArgumentException if duplicate keys or values were added
458     */
459    @Override
460    public ImmutableBiMap<K, V> build() {
461      return buildOrThrow();
462    }
463
464    /**
465     * Returns a newly-created immutable bimap, or throws an exception if any key or value was added
466     * more than once. The iteration order of the returned bimap is the order in which entries were
467     * inserted into the builder, unless {@link #orderEntriesByValue} was called, in which case
468     * entries are sorted by value.
469     *
470     * @throws IllegalArgumentException if duplicate keys or values were added
471     * @since 31.0
472     */
473    @Override
474    public ImmutableBiMap<K, V> buildOrThrow() {
475      if (size == 0) {
476        return of();
477      }
478      if (valueComparator != null) {
479        if (entriesUsed) {
480          alternatingKeysAndValues = Arrays.copyOf(alternatingKeysAndValues, 2 * size);
481        }
482        sortEntries(alternatingKeysAndValues, size, valueComparator);
483      }
484      entriesUsed = true;
485      return new RegularImmutableBiMap<K, V>(alternatingKeysAndValues, size);
486    }
487
488    /**
489     * Throws {@link UnsupportedOperationException}. This method is inherited from {@link
490     * ImmutableMap.Builder}, but it does not make sense for bimaps.
491     *
492     * @throws UnsupportedOperationException always
493     * @deprecated This method does not make sense for bimaps and should not be called.
494     * @since 31.1
495     */
496    @DoNotCall
497    @Deprecated
498    @Override
499    public ImmutableBiMap<K, V> buildKeepingLast() {
500      throw new UnsupportedOperationException("Not supported for bimaps");
501    }
502  }
503
504  /**
505   * Returns an immutable bimap containing the same entries as {@code map}. If {@code map} somehow
506   * contains entries with duplicate keys (for example, if it is a {@code SortedMap} whose
507   * comparator is not <i>consistent with equals</i>), the results of this method are undefined.
508   *
509   * <p>The returned {@code BiMap} iterates over entries in the same order as the {@code entrySet}
510   * of the original map.
511   *
512   * <p>Despite the method name, this method attempts to avoid actually copying the data when it is
513   * safe to do so. The exact circumstances under which a copy will or will not be performed are
514   * undocumented and subject to change.
515   *
516   * @throws IllegalArgumentException if two keys have the same value or two values have the same
517   *     key
518   * @throws NullPointerException if any key or value in {@code map} is null
519   */
520  public static <K, V> ImmutableBiMap<K, V> copyOf(Map<? extends K, ? extends V> map) {
521    if (map instanceof ImmutableBiMap) {
522      @SuppressWarnings("unchecked") // safe since map is not writable
523      ImmutableBiMap<K, V> bimap = (ImmutableBiMap<K, V>) map;
524      // TODO(lowasser): if we need to make a copy of a BiMap because the
525      // forward map is a view, don't make a copy of the non-view delegate map
526      if (!bimap.isPartialView()) {
527        return bimap;
528      }
529    }
530    return copyOf(map.entrySet());
531  }
532
533  /**
534   * Returns an immutable bimap containing the given entries. The returned bimap iterates over
535   * entries in the same order as the original iterable.
536   *
537   * @throws IllegalArgumentException if two keys have the same value or two values have the same
538   *     key
539   * @throws NullPointerException if any key, value, or entry is null
540   * @since 19.0
541   */
542  public static <K, V> ImmutableBiMap<K, V> copyOf(
543      Iterable<? extends Entry<? extends K, ? extends V>> entries) {
544    int estimatedSize =
545        (entries instanceof Collection)
546            ? ((Collection<?>) entries).size()
547            : ImmutableCollection.Builder.DEFAULT_INITIAL_CAPACITY;
548    return new Builder<K, V>(estimatedSize).putAll(entries).build();
549  }
550
551  ImmutableBiMap() {}
552
553  /**
554   * {@inheritDoc}
555   *
556   * <p>The inverse of an {@code ImmutableBiMap} is another {@code ImmutableBiMap}.
557   */
558  @Override
559  public abstract ImmutableBiMap<V, K> inverse();
560
561  /**
562   * Returns an immutable set of the values in this map, in the same order they appear in {@link
563   * #entrySet}.
564   */
565  @Override
566  public ImmutableSet<V> values() {
567    return inverse().keySet();
568  }
569
570  @Override
571  final ImmutableSet<V> createValues() {
572    throw new AssertionError("should never be called");
573  }
574
575  /**
576   * Guaranteed to throw an exception and leave the bimap unmodified.
577   *
578   * @throws UnsupportedOperationException always
579   * @deprecated Unsupported operation.
580   */
581  @CanIgnoreReturnValue
582  @Deprecated
583  @Override
584  @DoNotCall("Always throws UnsupportedOperationException")
585  public final @Nullable V forcePut(K key, V value) {
586    throw new UnsupportedOperationException();
587  }
588
589  /**
590   * Serialized type for all ImmutableBiMap instances. It captures the logical contents and they are
591   * reconstructed using public factory methods. This ensures that the implementation types remain
592   * as implementation details.
593   *
594   * <p>Since the bimap is immutable, ImmutableBiMap doesn't require special logic for keeping the
595   * bimap and its inverse in sync during serialization, the way AbstractBiMap does.
596   */
597  @J2ktIncompatible // serialization
598  private static class SerializedForm<K, V> extends ImmutableMap.SerializedForm<K, V> {
599    SerializedForm(ImmutableBiMap<K, V> bimap) {
600      super(bimap);
601    }
602
603    @Override
604    Builder<K, V> makeBuilder(int size) {
605      return new Builder<>(size);
606    }
607
608    private static final long serialVersionUID = 0;
609  }
610
611  @Override
612  @J2ktIncompatible // serialization
613  Object writeReplace() {
614    return new SerializedForm<>(this);
615  }
616
617  @J2ktIncompatible // serialization
618  private void readObject(ObjectInputStream stream) throws InvalidObjectException {
619    throw new InvalidObjectException("Use SerializedForm");
620  }
621
622  /**
623   * Not supported. Use {@link #toImmutableBiMap} instead. This method exists only to hide {@link
624   * ImmutableMap#toImmutableMap(Function, Function)} from consumers of {@code ImmutableBiMap}.
625   *
626   * @throws UnsupportedOperationException always
627   * @deprecated Use {@link ImmutableBiMap#toImmutableBiMap}.
628   * @since 33.2.0 (available since 21.0 in guava-jre)
629   */
630  @Deprecated
631  @DoNotCall("Use toImmutableBiMap")
632  @SuppressWarnings("Java7ApiChecker")
633  @IgnoreJRERequirement // Users will use this only if they're already using streams.
634  public static <T extends @Nullable Object, K, V>
635      Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
636          Function<? super T, ? extends K> keyFunction,
637          Function<? super T, ? extends V> valueFunction) {
638    throw new UnsupportedOperationException();
639  }
640
641  /**
642   * Not supported. This method does not make sense for {@code BiMap}. This method exists only to
643   * hide {@link ImmutableMap#toImmutableMap(Function, Function, BinaryOperator)} from consumers of
644   * {@code ImmutableBiMap}.
645   *
646   * @throws UnsupportedOperationException always
647   * @deprecated
648   * @since 33.2.0 (available since 21.0 in guava-jre)
649   */
650  @Deprecated
651  @DoNotCall("Use toImmutableBiMap")
652  @SuppressWarnings("Java7ApiChecker")
653  @IgnoreJRERequirement // Users will use this only if they're already using streams.
654  public static <T extends @Nullable Object, K, V>
655      Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
656          Function<? super T, ? extends K> keyFunction,
657          Function<? super T, ? extends V> valueFunction,
658          BinaryOperator<V> mergeFunction) {
659    throw new UnsupportedOperationException();
660  }
661
662  private static final long serialVersionUID = 0xdecaf;
663}