Home | History | Annotate | Download | only in collect
      1 /*
      2  * Copyright (C) 2007 Google Inc.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  * http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.google.common.collect;
     18 
     19 import com.google.common.annotations.GwtCompatible;
     20 
     21 import java.util.Collection;
     22 import java.util.List;
     23 import java.util.Map;
     24 
     25 import javax.annotation.Nullable;
     26 
     27 /**
     28  * Basic implementation of the {@link ListMultimap} interface. It's a wrapper
     29  * around {@link AbstractMultimap} that converts the returned collections into
     30  * {@code Lists}. The {@link #createCollection} method must return a {@code
     31  * List}.
     32  *
     33  * @author Jared Levy
     34  * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
     35  */
     36 @GwtCompatible
     37 abstract class AbstractListMultimap<K, V>
     38     extends AbstractMultimap<K, V> implements ListMultimap<K, V> {
     39   /**
     40    * Creates a new multimap that uses the provided map.
     41    *
     42    * @param map place to store the mapping from each key to its corresponding
     43    *     values
     44    */
     45   protected AbstractListMultimap(Map<K, Collection<V>> map) {
     46     super(map);
     47   }
     48 
     49   @Override abstract List<V> createCollection();
     50 
     51   @Override public List<V> get(@Nullable K key) {
     52     return (List<V>) super.get(key);
     53   }
     54 
     55   @Override public List<V> removeAll(@Nullable Object key) {
     56     return (List<V>) super.removeAll(key);
     57   }
     58 
     59   @Override public List<V> replaceValues(
     60       @Nullable K key, Iterable<? extends V> values) {
     61     return (List<V>) super.replaceValues(key, values);
     62   }
     63 
     64   /**
     65    * Stores a key-value pair in the multimap.
     66    *
     67    * @param key key to store in the multimap
     68    * @param value value to store in the multimap
     69    * @return {@code true} always
     70    */
     71   @Override public boolean put(@Nullable K key, @Nullable V value) {
     72     return super.put(key, value);
     73   }
     74 
     75   /**
     76    * Compares the specified object to this multimap for equality.
     77    *
     78    * <p>Two {@code ListMultimap} instances are equal if, for each key, they
     79    * contain the same values in the same order. If the value orderings disagree,
     80    * the multimaps will not be considered equal.
     81    */
     82   @Override public boolean equals(@Nullable Object object) {
     83     return super.equals(object);
     84   }
     85 
     86   private static final long serialVersionUID = 6588350623831699109L;
     87 }
     88