1090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/* 21d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * Copyright (C) 2007 The Guava Authors 3090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 4090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Licensed under the Apache License, Version 2.0 (the "License"); 5090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * you may not use this file except in compliance with the License. 6090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * You may obtain a copy of the License at 7090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 8090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 9090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 10090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Unless required by applicable law or agreed to in writing, software 11090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 12090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * See the License for the specific language governing permissions and 14090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * limitations under the License. 15090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 16090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 17090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonpackage com.google.common.collect; 18090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 19090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport com.google.common.annotations.GwtCompatible; 20090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 21090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Collection; 22090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.List; 23090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport java.util.Map; 24090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 25090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonimport javax.annotation.Nullable; 26090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 27090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson/** 28090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Basic implementation of the {@link ListMultimap} interface. It's a wrapper 29090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * around {@link AbstractMultimap} that converts the returned collections into 30090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * {@code Lists}. The {@link #createCollection} method must return a {@code 31090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * List}. 32090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 33090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @author Jared Levy 341d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * @since 2.0 (imported from Google Collections Library) 35090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 36090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson@GwtCompatible 37090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilsonabstract class AbstractListMultimap<K, V> 38090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson extends AbstractMultimap<K, V> implements ListMultimap<K, V> { 39090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson /** 40090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Creates a new multimap that uses the provided map. 41090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 42090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @param map place to store the mapping from each key to its corresponding 43090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * values 44090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 45090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson protected AbstractListMultimap(Map<K, Collection<V>> map) { 46090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson super(map); 47090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 48090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 49090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override abstract List<V> createCollection(); 50090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 511d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert // Following Javadoc copied from ListMultimap. 521d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 531d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 541d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@inheritDoc} 551d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 561d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Because the values for a given key may have duplicates and follow the 571d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * insertion ordering, this method returns a {@link List}, instead of the 581d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@link Collection} specified in the {@link Multimap} interface. 591d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 60090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override public List<V> get(@Nullable K key) { 61090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson return (List<V>) super.get(key); 62090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 63090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 641d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 651d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@inheritDoc} 661d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 671d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Because the values for a given key may have duplicates and follow the 681d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * insertion ordering, this method returns a {@link List}, instead of the 691d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@link Collection} specified in the {@link Multimap} interface. 701d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 71090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override public List<V> removeAll(@Nullable Object key) { 72090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson return (List<V>) super.removeAll(key); 73090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 74090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 751d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 761d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@inheritDoc} 771d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 781d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Because the values for a given key may have duplicates and follow the 791d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * insertion ordering, this method returns a {@link List}, instead of the 801d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@link Collection} specified in the {@link Multimap} interface. 811d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 82090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override public List<V> replaceValues( 83090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Nullable K key, Iterable<? extends V> values) { 84090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson return (List<V>) super.replaceValues(key, values); 85090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 86090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 87090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson /** 88090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Stores a key-value pair in the multimap. 89090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 90090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @param key key to store in the multimap 91090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @param value value to store in the multimap 92090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * @return {@code true} always 93090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 94090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override public boolean put(@Nullable K key, @Nullable V value) { 95090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson return super.put(key, value); 96090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 97090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson 98090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson /** 991d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * {@inheritDoc} 1001d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * 1011d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * <p>Though the method signature doesn't say so explicitly, the returned map 1021d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert * has {@link List} values. 1031d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert */ 1041d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert @Override public Map<K, Collection<V>> asMap() { 1051d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert return super.asMap(); 1061d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert } 1071d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1081d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert /** 109090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * Compares the specified object to this multimap for equality. 110090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * 111090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * <p>Two {@code ListMultimap} instances are equal if, for each key, they 112090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * contain the same values in the same order. If the value orderings disagree, 113090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson * the multimaps will not be considered equal. 114090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson */ 115090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson @Override public boolean equals(@Nullable Object object) { 116090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson return super.equals(object); 117090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson } 1181d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert 1191d580d0f6ee4f21eb309ba7b509d2c6d671c4044Bjorn Bringert private static final long serialVersionUID = 6588350623831699109L; 120090f9b4c879985bc747c214f82c62471e60c7742Jesse Wilson} 121