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.Map;
     23 import java.util.Set;
     24 
     25 import javax.annotation.Nullable;
     26 
     27 /**
     28  * A {@code Multimap} that cannot hold duplicate key-value pairs. Adding a
     29  * key-value pair that's already in the multimap has no effect.
     30  *
     31  * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods
     32  * each return a {@link Set} of values, while {@link #entries} returns a {@code
     33  * Set} of map entries. Though the method signature doesn't say so explicitly,
     34  * the map returned by {@link #asMap} has {@code Set} values.
     35  *
     36  * @author Jared Levy
     37  * @since 2010.01.04 <b>stable</b> (imported from Google Collections Library)
     38  */
     39 @GwtCompatible
     40 public interface SetMultimap<K, V> extends Multimap<K, V> {
     41   /**
     42    * {@inheritDoc}
     43    *
     44    * <p>Because a {@code SetMultimap} has unique values for a given key, this
     45    * method returns a {@link Set}, instead of the {@link java.util.Collection}
     46    * specified in the {@link Multimap} interface.
     47    */
     48   Set<V> get(@Nullable K key);
     49 
     50   /**
     51    * {@inheritDoc}
     52    *
     53    * <p>Because a {@code SetMultimap} has unique values for a given key, this
     54    * method returns a {@link Set}, instead of the {@link java.util.Collection}
     55    * specified in the {@link Multimap} interface.
     56    */
     57   Set<V> removeAll(@Nullable Object key);
     58 
     59   /**
     60    * {@inheritDoc}
     61    *
     62    * <p>Because a {@code SetMultimap} has unique values for a given key, this
     63    * method returns a {@link Set}, instead of the {@link java.util.Collection}
     64    * specified in the {@link Multimap} interface.
     65    *
     66    * <p>Any duplicates in {@code values} will be stored in the multimap once.
     67    */
     68   Set<V> replaceValues(K key, Iterable<? extends V> values);
     69 
     70   /**
     71    * {@inheritDoc}
     72    *
     73    * <p>Because a {@code SetMultimap} has unique values for a given key, this
     74    * method returns a {@link Set}, instead of the {@link java.util.Collection}
     75    * specified in the {@link Multimap} interface.
     76    */
     77   Set<Map.Entry<K, V>> entries();
     78 
     79   /**
     80    * {@inheritDoc}
     81    *
     82    * <p>Though the method signature doesn't say so explicitly, the returned map
     83    * has {@link Set} values.
     84    */
     85   Map<K, Collection<V>> asMap();
     86 
     87   /**
     88    * Compares the specified object to this multimap for equality.
     89    *
     90    * <p>Two {@code SetMultimap} instances are equal if, for each key, they
     91    * contain the same values. Equality does not depend on the ordering of keys
     92    * or values.
     93    */
     94   boolean equals(@Nullable Object obj);
     95 }
     96