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

Class Class, % Method, % Line, %
FilteredMultimapValues 0% (0/1) 0% (0/8) 0% (0/24)


1 /* 2  * Copyright (C) 2013 The Guava Authors 3  * 4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5  * in compliance with the License. You may obtain a copy of the License at 6  * 7  * http://www.apache.org/licenses/LICENSE-2.0 8  * 9  * Unless required by applicable law or agreed to in writing, software distributed under the License 10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11  * or implied. See the License for the specific language governing permissions and limitations under 12  * the License. 13  */ 14  15 package com.google.common.collect; 16  17 import static com.google.common.base.Preconditions.checkNotNull; 18  19 import com.google.common.annotations.GwtCompatible; 20 import com.google.common.base.Objects; 21 import com.google.common.base.Predicate; 22 import com.google.common.base.Predicates; 23 import com.google.j2objc.annotations.Weak; 24 import java.util.AbstractCollection; 25 import java.util.Collection; 26 import java.util.Iterator; 27 import java.util.Map.Entry; 28 import org.checkerframework.checker.nullness.qual.Nullable; 29  30 /** 31  * Implementation for {@link FilteredMultimap#values()}. 32  * 33  * @author Louis Wasserman 34  */ 35 @GwtCompatible 36 final class FilteredMultimapValues<K, V> extends AbstractCollection<V> { 37  @Weak private final FilteredMultimap<K, V> multimap; 38  39  FilteredMultimapValues(FilteredMultimap<K, V> multimap) { 40  this.multimap = checkNotNull(multimap); 41  } 42  43  @Override 44  public Iterator<V> iterator() { 45  return Maps.valueIterator(multimap.entries().iterator()); 46  } 47  48  @Override 49  public boolean contains(@Nullable Object o) { 50  return multimap.containsValue(o); 51  } 52  53  @Override 54  public int size() { 55  return multimap.size(); 56  } 57  58  @Override 59  public boolean remove(@Nullable Object o) { 60  Predicate<? super Entry<K, V>> entryPredicate = multimap.entryPredicate(); 61  for (Iterator<Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator(); 62  unfilteredItr.hasNext(); ) { 63  Entry<K, V> entry = unfilteredItr.next(); 64  if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) { 65  unfilteredItr.remove(); 66  return true; 67  } 68  } 69  return false; 70  } 71  72  @Override 73  public boolean removeAll(Collection<?> c) { 74  return Iterables.removeIf( 75  multimap.unfiltered().entries(), 76  // explicit <Entry<K, V>> is required to build with JDK6 77  Predicates.<Entry<K, V>>and( 78  multimap.entryPredicate(), Maps.<V>valuePredicateOnEntries(Predicates.in(c)))); 79  } 80  81  @Override 82  public boolean retainAll(Collection<?> c) { 83  return Iterables.removeIf( 84  multimap.unfiltered().entries(), 85  // explicit <Entry<K, V>> is required to build with JDK6 86  Predicates.<Entry<K, V>>and( 87  multimap.entryPredicate(), 88  Maps.<V>valuePredicateOnEntries(Predicates.not(Predicates.in(c))))); 89  } 90  91  @Override 92  public void clear() { 93  multimap.clear(); 94  } 95 }