Coverage Summary for Class: AbstractListMultimap (com.google.common.collect)
| Class | Class, % | Method, % | Line, % |
|---|---|---|---|
| AbstractListMultimap | 100% (1/1) | 80% (8/10) | 81.8% (9/11) |
1 /* 2 * Copyright (C) 2007 The Guava Authors 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 import com.google.errorprone.annotations.CanIgnoreReturnValue; 21 import java.util.Collection; 22 import java.util.Collections; 23 import java.util.List; 24 import java.util.Map; 25 import org.checkerframework.checker.nullness.qual.Nullable; 26 27 /** 28 * Basic implementation of the {@link ListMultimap} interface. It's a wrapper around {@link 29 * AbstractMapBasedMultimap} that converts the returned collections into {@code Lists}. The {@link 30 * #createCollection} method must return a {@code List}. 31 * 32 * @author Jared Levy 33 * @since 2.0 34 */ 35 @GwtCompatible 36 abstract class AbstractListMultimap<K, V> extends AbstractMapBasedMultimap<K, V> 37 implements ListMultimap<K, V> { 38 /** 39 * Creates a new multimap that uses the provided map. 40 * 41 * @param map place to store the mapping from each key to its corresponding values 42 */ 43 protected AbstractListMultimap(Map<K, Collection<V>> map) { 44 super(map); 45 } 46 47 @Override 48 abstract List<V> createCollection(); 49 50 @Override 51 List<V> createUnmodifiableEmptyCollection() { 52 return Collections.emptyList(); 53 } 54 55 @Override 56 <E> Collection<E> unmodifiableCollectionSubclass(Collection<E> collection) { 57 return Collections.unmodifiableList((List<E>) collection); 58 } 59 60 @Override 61 Collection<V> wrapCollection(K key, Collection<V> collection) { 62 return wrapList(key, (List<V>) collection, null); 63 } 64 65 // Following Javadoc copied from ListMultimap. 66 67 /** 68 * {@inheritDoc} 69 * 70 * <p>Because the values for a given key may have duplicates and follow the insertion ordering, 71 * this method returns a {@link List}, instead of the {@link Collection} specified in the {@link 72 * Multimap} interface. 73 */ 74 @Override 75 public List<V> get(@Nullable K key) { 76 return (List<V>) super.get(key); 77 } 78 79 /** 80 * {@inheritDoc} 81 * 82 * <p>Because the values for a given key may have duplicates and follow the insertion ordering, 83 * this method returns a {@link List}, instead of the {@link Collection} specified in the {@link 84 * Multimap} interface. 85 */ 86 @CanIgnoreReturnValue 87 @Override 88 public List<V> removeAll(@Nullable Object key) { 89 return (List<V>) super.removeAll(key); 90 } 91 92 /** 93 * {@inheritDoc} 94 * 95 * <p>Because the values for a given key may have duplicates and follow the insertion ordering, 96 * this method returns a {@link List}, instead of the {@link Collection} specified in the {@link 97 * Multimap} interface. 98 */ 99 @CanIgnoreReturnValue 100 @Override 101 public List<V> replaceValues(@Nullable K key, Iterable<? extends V> values) { 102 return (List<V>) super.replaceValues(key, values); 103 } 104 105 /** 106 * Stores a key-value pair in the multimap. 107 * 108 * @param key key to store in the multimap 109 * @param value value to store in the multimap 110 * @return {@code true} always 111 */ 112 @CanIgnoreReturnValue 113 @Override 114 public boolean put(@Nullable K key, @Nullable V value) { 115 return super.put(key, value); 116 } 117 118 /** 119 * {@inheritDoc} 120 * 121 * <p>Though the method signature doesn't say so explicitly, the returned map has {@link List} 122 * values. 123 */ 124 @Override 125 public Map<K, Collection<V>> asMap() { 126 return super.asMap(); 127 } 128 129 /** 130 * Compares the specified object to this multimap for equality. 131 * 132 * <p>Two {@code ListMultimap} instances are equal if, for each key, they contain the same values 133 * in the same order. If the value orderings disagree, the multimaps will not be considered equal. 134 */ 135 @Override 136 public boolean equals(@Nullable Object object) { 137 return super.equals(object); 138 } 139 140 private static final long serialVersionUID = 6588350623831699109L; 141 }