diff options
author | Paul Duffin <paulduffin@google.com> | 2015-01-23 14:38:46 +0000 |
---|---|---|
committer | Paul Duffin <paulduffin@google.com> | 2015-02-12 20:44:38 +0000 |
commit | 0888a09821a98ac0680fad765217302858e70fa4 (patch) | |
tree | 6f6fc4b017cd2d7870406f435fa44796fb3ac1f1 /guava/src/com/google/common/collect/FilteredKeyMultimap.java | |
parent | 8733ee5d13d66d24cf2cce4f23fc1be2aac2f49e (diff) | |
download | android_external_guava-0888a09821a98ac0680fad765217302858e70fa4.tar.gz android_external_guava-0888a09821a98ac0680fad765217302858e70fa4.tar.bz2 android_external_guava-0888a09821a98ac0680fad765217302858e70fa4.zip |
Upgraded Guava to unmodified jdk5-backport-v17.0-compatibility
This simply copies the Guava source for jdk5-backport-v17.0-compatibility
straight from the github repository into this one.
See https://github.com/google/guava.git
Additional commits will be made which will allow this to compile
on Android.
Change-Id: I07db3bd92bb7370cad9d9b9c9cc4d67733b079b6
Diffstat (limited to 'guava/src/com/google/common/collect/FilteredKeyMultimap.java')
-rw-r--r-- | guava/src/com/google/common/collect/FilteredKeyMultimap.java | 99 |
1 files changed, 46 insertions, 53 deletions
diff --git a/guava/src/com/google/common/collect/FilteredKeyMultimap.java b/guava/src/com/google/common/collect/FilteredKeyMultimap.java index 1fe2e38..3788b72 100644 --- a/guava/src/com/google/common/collect/FilteredKeyMultimap.java +++ b/guava/src/com/google/common/collect/FilteredKeyMultimap.java @@ -1,17 +1,15 @@ /* * Copyright (C) 2012 The Guava Authors * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.google.common.collect; @@ -21,7 +19,6 @@ import static com.google.common.base.Preconditions.checkPositionIndex; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Predicate; -import com.google.common.base.Predicates; import java.util.Collection; import java.util.Collections; @@ -39,19 +36,26 @@ import javax.annotation.Nullable; * @author Louis Wasserman */ @GwtCompatible -class FilteredKeyMultimap<K, V> extends FilteredMultimap<K, V> { +class FilteredKeyMultimap<K, V> extends AbstractMultimap<K, V> implements FilteredMultimap<K, V> { + final Multimap<K, V> unfiltered; final Predicate<? super K> keyPredicate; FilteredKeyMultimap(Multimap<K, V> unfiltered, Predicate<? super K> keyPredicate) { - super(unfiltered); + this.unfiltered = checkNotNull(unfiltered); this.keyPredicate = checkNotNull(keyPredicate); } @Override - Predicate<? super Entry<K, V>> entryPredicate() { - return Predicates.compose(keyPredicate, Maps.<K> keyFunction()); + public Multimap<K, V> unfiltered() { + return unfiltered; } + @Override + public Predicate<? super Entry<K, V>> entryPredicate() { + return Maps.keyPredicateOnEntries(keyPredicate); + } + + @Override public int size() { int size = 0; for (Collection<V> collection : asMap().values()) { @@ -60,16 +64,17 @@ class FilteredKeyMultimap<K, V> extends FilteredMultimap<K, V> { return size; } + @Override public boolean containsKey(@Nullable Object key) { if (unfiltered.containsKey(key)) { - @SuppressWarnings("unchecked") - // k is equal to a K, if not one itself + @SuppressWarnings("unchecked") // k is equal to a K, if not one itself K k = (K) key; return keyPredicate.apply(k); } return false; } + @Override public Collection<V> removeAll(Object key) { return containsKey(key) ? unfiltered.removeAll(key) : unmodifiableEmptyCollection(); } @@ -82,6 +87,7 @@ class FilteredKeyMultimap<K, V> extends FilteredMultimap<K, V> { } } + @Override public void clear() { keySet().clear(); } @@ -91,6 +97,7 @@ class FilteredKeyMultimap<K, V> extends FilteredMultimap<K, V> { return Sets.filter(unfiltered.keySet(), keyPredicate); } + @Override public Collection<V> get(K key) { if (keyPredicate.apply(key)) { return unfiltered.get(key); @@ -165,52 +172,38 @@ class FilteredKeyMultimap<K, V> extends FilteredMultimap<K, V> { @Override Iterator<Entry<K, V>> entryIterator() { - return Iterators.filter(unfiltered.entries().iterator(), - Predicates.compose(keyPredicate, Maps.<K> keyFunction())); + throw new AssertionError("should never be called"); } @Override Collection<Entry<K, V>> createEntries() { - return new Multimaps.Entries<K, V>() { - - @Override - Multimap<K, V> multimap() { - return FilteredKeyMultimap.this; - } + return new Entries(); + } - @Override - public Iterator<Entry<K, V>> iterator() { - return entryIterator(); - } + class Entries extends ForwardingCollection<Entry<K, V>> { + @Override + protected Collection<Entry<K, V>> delegate() { + return Collections2.filter(unfiltered.entries(), entryPredicate()); + } - @Override - @SuppressWarnings("unchecked") - public boolean remove(@Nullable Object o) { - if (o instanceof Entry) { - Entry<?, ?> entry = (Entry<?, ?>) o; - if (unfiltered.containsEntry(entry.getKey(), entry.getValue()) - && keyPredicate.apply((K) entry.getKey())) { - return unfiltered.remove(entry.getKey(), entry.getValue()); - } + @Override + @SuppressWarnings("unchecked") + public boolean remove(@Nullable Object o) { + if (o instanceof Entry) { + Entry<?, ?> entry = (Entry<?, ?>) o; + if (unfiltered.containsKey(entry.getKey()) + // if this holds, then we know entry.getKey() is a K + && keyPredicate.apply((K) entry.getKey())) { + return unfiltered.remove(entry.getKey(), entry.getValue()); } - return false; - } - - @Override - public boolean removeAll(Collection<?> c) { - Predicate<Entry<K, ?>> combinedPredicate = Predicates.and( - Predicates.compose(keyPredicate, Maps.<K> keyFunction()), Predicates.in(c)); - return Iterators.removeIf(unfiltered.entries().iterator(), combinedPredicate); } - - @Override - public boolean retainAll(Collection<?> c) { - Predicate<Entry<K, ?>> combinedPredicate = Predicates.and( - Predicates.compose(keyPredicate, Maps.<K> keyFunction()), - Predicates.not(Predicates.in(c))); - return Iterators.removeIf(unfiltered.entries().iterator(), combinedPredicate); - } - }; + return false; + } + } + + @Override + Collection<V> createValues() { + return new FilteredMultimapValues<K, V>(this); } @Override |