Coverage Summary for Class: AbstractSetMultimap (com.google.common.collect)

Class Class, % Method, % Line, %
AbstractSetMultimap 100% (1/1) 54.5% (6/11) 58.3% (7/12)


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.Map; 24 import java.util.Map.Entry; 25 import java.util.Set; 26 import org.checkerframework.checker.nullness.qual.Nullable; 27  28 /** 29  * Basic implementation of the {@link SetMultimap} interface. It's a wrapper around {@link 30  * AbstractMapBasedMultimap} that converts the returned collections into {@code Sets}. The {@link 31  * #createCollection} method must return a {@code Set}. 32  * 33  * @author Jared Levy 34  */ 35 @GwtCompatible 36 abstract class AbstractSetMultimap<K, V> extends AbstractMapBasedMultimap<K, V> 37  implements SetMultimap<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 AbstractSetMultimap(Map<K, Collection<V>> map) { 44  super(map); 45  } 46  47  @Override 48  abstract Set<V> createCollection(); 49  50  @Override 51  Set<V> createUnmodifiableEmptyCollection() { 52  return Collections.emptySet(); 53  } 54  55  @Override 56  <E> Collection<E> unmodifiableCollectionSubclass(Collection<E> collection) { 57  return Collections.unmodifiableSet((Set<E>) collection); 58  } 59  60  @Override 61  Collection<V> wrapCollection(K key, Collection<V> collection) { 62  return new WrappedSet(key, (Set<V>) collection); 63  } 64  65  // Following Javadoc copied from SetMultimap. 66  67  /** 68  * {@inheritDoc} 69  * 70  * <p>Because a {@code SetMultimap} has unique values for a given key, this method returns a 71  * {@link Set}, instead of the {@link Collection} specified in the {@link Multimap} interface. 72  */ 73  @Override 74  public Set<V> get(@Nullable K key) { 75  return (Set<V>) super.get(key); 76  } 77  78  /** 79  * {@inheritDoc} 80  * 81  * <p>Because a {@code SetMultimap} has unique values for a given key, this method returns a 82  * {@link Set}, instead of the {@link Collection} specified in the {@link Multimap} interface. 83  */ 84  @Override 85  public Set<Entry<K, V>> entries() { 86  return (Set<Entry<K, V>>) super.entries(); 87  } 88  89  /** 90  * {@inheritDoc} 91  * 92  * <p>Because a {@code SetMultimap} has unique values for a given key, this method returns a 93  * {@link Set}, instead of the {@link Collection} specified in the {@link Multimap} interface. 94  */ 95  @CanIgnoreReturnValue 96  @Override 97  public Set<V> removeAll(@Nullable Object key) { 98  return (Set<V>) super.removeAll(key); 99  } 100  101  /** 102  * {@inheritDoc} 103  * 104  * <p>Because a {@code SetMultimap} has unique values for a given key, this method returns a 105  * {@link Set}, instead of the {@link Collection} specified in the {@link Multimap} interface. 106  * 107  * <p>Any duplicates in {@code values} will be stored in the multimap once. 108  */ 109  @CanIgnoreReturnValue 110  @Override 111  public Set<V> replaceValues(@Nullable K key, Iterable<? extends V> values) { 112  return (Set<V>) super.replaceValues(key, values); 113  } 114  115  /** 116  * {@inheritDoc} 117  * 118  * <p>Though the method signature doesn't say so explicitly, the returned map has {@link Set} 119  * values. 120  */ 121  @Override 122  public Map<K, Collection<V>> asMap() { 123  return super.asMap(); 124  } 125  126  /** 127  * Stores a key-value pair in the multimap. 128  * 129  * @param key key to store in the multimap 130  * @param value value to store in the multimap 131  * @return {@code true} if the method increased the size of the multimap, or {@code false} if the 132  * multimap already contained the key-value pair 133  */ 134  @CanIgnoreReturnValue 135  @Override 136  public boolean put(@Nullable K key, @Nullable V value) { 137  return super.put(key, value); 138  } 139  140  /** 141  * Compares the specified object to this multimap for equality. 142  * 143  * <p>Two {@code SetMultimap} instances are equal if, for each key, they contain the same values. 144  * Equality does not depend on the ordering of keys or values. 145  */ 146  @Override 147  public boolean equals(@Nullable Object object) { 148  return super.equals(object); 149  } 150  151  private static final long serialVersionUID = 7431625294878419160L; 152 }