/*
 * Copyright (C) 2013 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
 *
 * 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.
 */

package com.google.common.collect;

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.common.annotations.GwtCompatible;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;

import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;

import javax.annotation.Nullable;

/**
 * Implementation for {@link FilteredMultimap#values()}.
 * 
 * @author Louis Wasserman
 */
@GwtCompatible
final class FilteredMultimapValues<K, V> extends AbstractCollection<V> {
  private final FilteredMultimap<K, V> multimap;

  FilteredMultimapValues(FilteredMultimap<K, V> multimap) {
    this.multimap = checkNotNull(multimap);
  }

  @Override
  public Iterator<V> iterator() {
    return Maps.valueIterator(multimap.entries().iterator());
  }

  @Override
  public boolean contains(@Nullable Object o) {
    return multimap.containsValue(o);
  }

  @Override
  public int size() {
    return multimap.size();
  }

  @Override
  public boolean remove(@Nullable Object o) {
    Predicate<? super Map.Entry<K, V>> entryPredicate = multimap.entryPredicate();
    for (Iterator<Map.Entry<K, V>> unfilteredItr = multimap.unfiltered().entries().iterator();
        unfilteredItr.hasNext();) {
      Map.Entry<K, V> entry = unfilteredItr.next();
      if (entryPredicate.apply(entry) && Objects.equal(entry.getValue(), o)) {
        unfilteredItr.remove();
        return true;
      }
    }
    return false;
  }

  @Override
  public boolean removeAll(Collection<?> c) {
    return Iterables.removeIf(multimap.unfiltered().entries(),
        Predicates.and(multimap.entryPredicate(),
            Maps.<V>valuePredicateOnEntries(Predicates.in(c))));
  }

  @Override
  public boolean retainAll(Collection<?> c) {
    return Iterables.removeIf(multimap.unfiltered().entries(),
        Predicates.and(multimap.entryPredicate(),
            Maps.<V>valuePredicateOnEntries(Predicates.not(Predicates.in(c)))));
  }

  @Override
  public void clear() {
    multimap.clear();
  }
}

@@ -980,16 +980,44 @@
 til.Map;
+%0Aimport java.util.Map.Entry;
 %0A%0Aimport
@@ -1751,20 +1751,16 @@
 ? super 
-Map.
 Entry%3CK,
@@ -1826,20 +1826,16 @@
 terator%3C
-Map.
 Entry%3CK,
@@ -2269,32 +2269,97 @@
 ed().entries(),%0A
+        // explicit %3CEntry%3CK, V%3E%3E is required to build with JDK6%0A
         Predicat
@@ -2353,32 +2353,45 @@
      Predicates.
+%3CEntry%3CK, V%3E%3E
 and(multimap.ent
@@ -2588,32 +2588,97 @@
 ed().entries(),%0A
+        // explicit %3CEntry%3CK, V%3E%3E is required to build with JDK6%0A
         Predicat
@@ -2680,16 +2680,29 @@
 dicates.
+%3CEntry%3CK, V%3E%3E
 and(mult

Add explicit type parameters in FilteredMultimapValues to make JDK6 happy. ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=46951071