001/*
002 * Copyright (C) 2007 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 com.google.common.annotations.GwtCompatible;
020import com.google.errorprone.annotations.CanIgnoreReturnValue;
021import java.util.Collection;
022import java.util.List;
023import java.util.Map;
024import javax.annotation.CheckForNull;
025import org.checkerframework.checker.nullness.qual.Nullable;
026
027/**
028 * A {@code Multimap} that can hold duplicate key-value pairs and that maintains the insertion
029 * ordering of values for a given key. See the {@link Multimap} documentation for information common
030 * to all multimaps.
031 *
032 * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods each return a {@link
033 * List} of values. Though the method signature doesn't say so explicitly, the map returned by
034 * {@link #asMap} has {@code List} values.
035 *
036 * <p>See the Guava User Guide article on <a href=
037 * "https://github.com/google/guava/wiki/NewCollectionTypesExplained#multimap">{@code Multimap}</a>.
038 *
039 * @author Jared Levy
040 * @since 2.0
041 */
042@GwtCompatible
043@ElementTypesAreNonnullByDefault
044public interface ListMultimap<K extends @Nullable Object, V extends @Nullable Object>
045    extends Multimap<K, V> {
046  /**
047   * {@inheritDoc}
048   *
049   * <p>Because the values for a given key may have duplicates and follow the insertion ordering,
050   * this method returns a {@link List}, instead of the {@link java.util.Collection} specified in
051   * the {@link Multimap} interface.
052   */
053  @Override
054  List<V> get(@ParametricNullness K key);
055
056  /**
057   * {@inheritDoc}
058   *
059   * <p>Because the values for a given key may have duplicates and follow the insertion ordering,
060   * this method returns a {@link List}, instead of the {@link java.util.Collection} specified in
061   * the {@link Multimap} interface.
062   */
063  @CanIgnoreReturnValue
064  @Override
065  List<V> removeAll(@CheckForNull Object key);
066
067  /**
068   * {@inheritDoc}
069   *
070   * <p>Because the values for a given key may have duplicates and follow the insertion ordering,
071   * this method returns a {@link List}, instead of the {@link java.util.Collection} specified in
072   * the {@link Multimap} interface.
073   */
074  @CanIgnoreReturnValue
075  @Override
076  List<V> replaceValues(@ParametricNullness K key, Iterable<? extends V> values);
077
078  /**
079   * {@inheritDoc}
080   *
081   * <p><b>Note:</b> The returned map's values are guaranteed to be of type {@link List}. To obtain
082   * this map with the more specific generic type {@code Map<K, List<V>>}, call {@link
083   * Multimaps#asMap(ListMultimap)} instead.
084   */
085  @Override
086  Map<K, Collection<V>> asMap();
087
088  /**
089   * Compares the specified object to this multimap for equality.
090   *
091   * <p>Two {@code ListMultimap} instances are equal if, for each key, they contain the same values
092   * in the same order. If the value orderings disagree, the multimaps will not be considered equal.
093   *
094   * <p>An empty {@code ListMultimap} is equal to any other empty {@code Multimap}, including an
095   * empty {@code SetMultimap}.
096   */
097  @Override
098  boolean equals(@CheckForNull Object obj);
099}