/* * Decompiled with CFR 0.152. */ package com.google.common.collect; import com.google.common.annotations.GwtCompatible; import com.google.common.base.Preconditions; import com.google.common.collect.Iterators; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.google.common.collect.Multimaps; import com.google.common.collect.Multiset; import com.google.common.collect.SetMultimap; import com.google.common.collect.Sets; import java.util.AbstractCollection; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Set; import javax.annotation.Nullable; @GwtCompatible abstract class AbstractMultimap implements Multimap { private transient Collection> entries; private transient Set keySet; private transient Multiset keys; private transient Collection values; private transient Map> asMap; AbstractMultimap() { } @Override public boolean isEmpty() { return this.size() == 0; } @Override public boolean containsValue(@Nullable Object value) { for (Collection collection : this.asMap().values()) { if (!collection.contains(value)) continue; return true; } return false; } @Override public boolean containsEntry(@Nullable Object key, @Nullable Object value) { Collection collection = this.asMap().get(key); return collection != null && collection.contains(value); } @Override public boolean remove(@Nullable Object key, @Nullable Object value) { Collection collection = this.asMap().get(key); return collection != null && collection.remove(value); } @Override public boolean put(@Nullable K key, @Nullable V value) { return this.get(key).add(value); } @Override public boolean putAll(@Nullable K key, Iterable values) { Preconditions.checkNotNull(values); if (values instanceof Collection) { Collection valueCollection = (Collection)values; return !valueCollection.isEmpty() && this.get(key).addAll(valueCollection); } Iterator valueItr = values.iterator(); return valueItr.hasNext() && Iterators.addAll(this.get(key), valueItr); } @Override public boolean putAll(Multimap multimap) { boolean changed = false; for (Map.Entry entry : multimap.entries()) { changed |= this.put(entry.getKey(), entry.getValue()); } return changed; } @Override public Collection replaceValues(@Nullable K key, Iterable values) { Preconditions.checkNotNull(values); Collection result = this.removeAll(key); this.putAll(key, values); return result; } @Override public Collection> entries() { Collection> result = this.entries; return result == null ? (this.entries = this.createEntries()) : result; } Collection> createEntries() { if (this instanceof SetMultimap) { return new EntrySet(); } return new Entries(); } abstract Iterator> entryIterator(); @Override public Set keySet() { Set result = this.keySet; return result == null ? (this.keySet = this.createKeySet()) : result; } Set createKeySet() { return new Maps.KeySet>(this.asMap()); } @Override public Multiset keys() { Multiset result = this.keys; return result == null ? (this.keys = this.createKeys()) : result; } Multiset createKeys() { return new Multimaps.Keys(this); } @Override public Collection values() { Collection result = this.values; return result == null ? (this.values = this.createValues()) : result; } Collection createValues() { return new Values(); } Iterator valueIterator() { return Maps.valueIterator(this.entries().iterator()); } @Override public Map> asMap() { Map>> result = this.asMap; return result == null ? (this.asMap = this.createAsMap()) : result; } abstract Map> createAsMap(); @Override public boolean equals(@Nullable Object object) { return Multimaps.equalsImpl(this, object); } @Override public int hashCode() { return this.asMap().hashCode(); } public String toString() { return this.asMap().toString(); } class Values extends AbstractCollection { Values() { } @Override public Iterator iterator() { return AbstractMultimap.this.valueIterator(); } @Override public int size() { return AbstractMultimap.this.size(); } @Override public boolean contains(@Nullable Object o) { return AbstractMultimap.this.containsValue(o); } @Override public void clear() { AbstractMultimap.this.clear(); } } private class EntrySet extends Entries implements Set> { private EntrySet() { } @Override public int hashCode() { return Sets.hashCodeImpl(this); } @Override public boolean equals(@Nullable Object obj) { return Sets.equalsImpl(this, obj); } } private class Entries extends Multimaps.Entries { private Entries() { } @Override Multimap multimap() { return AbstractMultimap.this; } @Override public Iterator> iterator() { return AbstractMultimap.this.entryIterator(); } } }