001 /* 002 * Copyright (C) 2007 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 package com.google.common.collect; 018 019 import com.google.common.annotations.GwtCompatible; 020 021 import java.util.Collection; 022 import java.util.Comparator; 023 import java.util.Map; 024 import java.util.Set; 025 import java.util.SortedSet; 026 027 import javax.annotation.Nullable; 028 029 /** 030 * A {@code SetMultimap} whose set of values for a given key are kept sorted; 031 * that is, they comprise a {@link SortedSet}. It cannot hold duplicate 032 * key-value pairs; adding a key-value pair that's already in the multimap has 033 * no effect. This interface does not specify the ordering of the multimap's 034 * keys. 035 * 036 * <p>The {@link #get}, {@link #removeAll}, and {@link #replaceValues} methods 037 * each return a {@link SortedSet} of values, while {@link Multimap#entries()} 038 * returns a {@link Set} of map entries. Though the method signature doesn't say 039 * so explicitly, the map returned by {@link #asMap} has {@code SortedSet} 040 * values. 041 * 042 * @author Jared Levy 043 * @since 2.0 (imported from Google Collections Library) 044 */ 045 @GwtCompatible 046 public interface SortedSetMultimap<K, V> extends SetMultimap<K, V> { 047 // Following Javadoc copied from Multimap. 048 049 /** 050 * Returns a collection view of all values associated with a key. If no 051 * mappings in the multimap have the provided key, an empty collection is 052 * returned. 053 * 054 * <p>Changes to the returned collection will update the underlying multimap, 055 * and vice versa. 056 * 057 * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given 058 * key, this method returns a {@link SortedSet}, instead of the 059 * {@link java.util.Collection} specified in the {@link Multimap} interface. 060 */ 061 @Override 062 SortedSet<V> get(@Nullable K key); 063 064 /** 065 * Removes all values associated with a given key. 066 * 067 * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given 068 * key, this method returns a {@link SortedSet}, instead of the 069 * {@link java.util.Collection} specified in the {@link Multimap} interface. 070 */ 071 @Override 072 SortedSet<V> removeAll(@Nullable Object key); 073 074 /** 075 * Stores a collection of values with the same key, replacing any existing 076 * values for that key. 077 * 078 * <p>Because a {@code SortedSetMultimap} has unique sorted values for a given 079 * key, this method returns a {@link SortedSet}, instead of the 080 * {@link java.util.Collection} specified in the {@link Multimap} interface. 081 * 082 * <p>Any duplicates in {@code values} will be stored in the multimap once. 083 */ 084 @Override 085 SortedSet<V> replaceValues(K key, Iterable<? extends V> values); 086 087 /** 088 * Returns a map view that associates each key with the corresponding values 089 * in the multimap. Changes to the returned map, such as element removal, will 090 * update the underlying multimap. The map does not support {@code setValue()} 091 * on its entries, {@code put}, or {@code putAll}. 092 * 093 * <p>When passed a key that is present in the map, {@code 094 * asMap().get(Object)} has the same behavior as {@link #get}, returning a 095 * live collection. When passed a key that is not present, however, {@code 096 * asMap().get(Object)} returns {@code null} instead of an empty collection. 097 * 098 * <p>Though the method signature doesn't say so explicitly, the returned map 099 * has {@link SortedSet} values. 100 */ 101 @Override 102 Map<K, Collection<V>> asMap(); 103 104 /** 105 * Returns the comparator that orders the multimap values, with {@code null} 106 * indicating that natural ordering is used. 107 */ 108 Comparator<? super V> valueComparator(); 109 }