package com.google.common.collect; import com.google.common.base.Objects; import com.google.common.collect.Sets; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.util.Arrays; import java.util.Collection; import java.util.ConcurrentModificationException; import java.util.Iterator; import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; /* loaded from: classes2.dex */ public final class LinkedHashMultimap extends LinkedHashMultimapGwtSerializationDependencies { private static final int DEFAULT_KEY_CAPACITY = 16; private static final int DEFAULT_VALUE_SET_CAPACITY = 2; static final double VALUE_SET_LOAD_FACTOR = 1.0d; private static final long serialVersionUID = 1; private transient ValueEntry multimapHeaderEntry; transient int valueSetCapacity; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public interface ValueSetLink { ValueSetLink getPredecessorInValueSet(); ValueSetLink getSuccessorInValueSet(); void setPredecessorInValueSet(ValueSetLink valueSetLink); void setSuccessorInValueSet(ValueSetLink valueSetLink); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap public final /* bridge */ /* synthetic */ Map asMap() { return super.asMap(); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean containsEntry(Object obj, Object obj2) { return super.containsEntry(obj, obj2); } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean containsKey(Object obj) { return super.containsKey(obj); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean containsValue(Object obj) { return super.containsValue(obj); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap, com.google.common.collect.ListMultimap public final /* bridge */ /* synthetic */ boolean equals(Object obj) { return super.equals(obj); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ Set get(Object obj) { return super.get(obj); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ int hashCode() { return super.hashCode(); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean isEmpty() { return super.isEmpty(); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ Multiset keys() { return super.keys(); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean put(Object obj, Object obj2) { return super.put(obj, obj2); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean putAll(Multimap multimap) { return super.putAll(multimap); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean putAll(Object obj, Iterable iterable) { return super.putAll(obj, iterable); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ boolean remove(Object obj, Object obj2) { return super.remove(obj, obj2); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ Set removeAll(Object obj) { return super.removeAll(obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ Collection replaceValues(Object obj, Iterable iterable) { return replaceValues((LinkedHashMultimap) obj, iterable); } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.Multimap public final /* bridge */ /* synthetic */ int size() { return super.size(); } @Override // com.google.common.collect.AbstractMultimap public final /* bridge */ /* synthetic */ String toString() { return super.toString(); } public static LinkedHashMultimap create() { return new LinkedHashMultimap<>(16, 2); } public static LinkedHashMultimap create(int i, int i2) { return new LinkedHashMultimap<>(Maps.capacity(i), Maps.capacity(i2)); } public static LinkedHashMultimap create(Multimap multimap) { LinkedHashMultimap create = create(multimap.keySet().size(), 2); create.putAll(multimap); return create; } /* JADX INFO: Access modifiers changed from: private */ public static void succeedsInValueSet(ValueSetLink valueSetLink, ValueSetLink valueSetLink2) { valueSetLink.setSuccessorInValueSet(valueSetLink2); valueSetLink2.setPredecessorInValueSet(valueSetLink); } /* JADX INFO: Access modifiers changed from: private */ public static void succeedsInMultimap(ValueEntry valueEntry, ValueEntry valueEntry2) { valueEntry.setSuccessorInMultimap(valueEntry2); valueEntry2.setPredecessorInMultimap(valueEntry); } /* JADX INFO: Access modifiers changed from: private */ public static void deleteFromValueSet(ValueSetLink valueSetLink) { succeedsInValueSet(valueSetLink.getPredecessorInValueSet(), valueSetLink.getSuccessorInValueSet()); } /* JADX INFO: Access modifiers changed from: private */ public static void deleteFromMultimap(ValueEntry valueEntry) { succeedsInMultimap(valueEntry.getPredecessorInMultimap(), valueEntry.getSuccessorInMultimap()); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class ValueEntry extends ImmutableEntry implements ValueSetLink { ValueEntry nextInValueBucket; ValueEntry predecessorInMultimap; ValueSetLink predecessorInValueSet; final int smearedValueHash; ValueEntry successorInMultimap; ValueSetLink successorInValueSet; ValueEntry(K k, V v, int i, ValueEntry valueEntry) { super(k, v); this.smearedValueHash = i; this.nextInValueBucket = valueEntry; } final boolean matchesValue(Object obj, int i) { return this.smearedValueHash == i && Objects.equal(getValue(), obj); } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final void setSuccessorInValueSet(ValueSetLink valueSetLink) { this.successorInValueSet = valueSetLink; } public final void setSuccessorInMultimap(ValueEntry valueEntry) { this.successorInMultimap = valueEntry; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final void setPredecessorInValueSet(ValueSetLink valueSetLink) { this.predecessorInValueSet = valueSetLink; } public final void setPredecessorInMultimap(ValueEntry valueEntry) { this.predecessorInMultimap = valueEntry; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final ValueSetLink getSuccessorInValueSet() { return this.successorInValueSet; } public final ValueEntry getSuccessorInMultimap() { return this.successorInMultimap; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final ValueSetLink getPredecessorInValueSet() { return this.predecessorInValueSet; } public final ValueEntry getPredecessorInMultimap() { return this.predecessorInMultimap; } } private LinkedHashMultimap(int i, int i2) { super(Platform.newLinkedHashMapWithExpectedSize(i)); this.valueSetCapacity = 2; CollectPreconditions.checkNonnegative(i2, "expectedValuesPerKey"); this.valueSetCapacity = i2; ValueEntry valueEntry = new ValueEntry<>(null, null, 0, null); this.multimapHeaderEntry = valueEntry; succeedsInMultimap(valueEntry, valueEntry); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap public final Set createCollection() { return Platform.newLinkedHashSetWithExpectedSize(this.valueSetCapacity); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMapBasedMultimap public final Collection createCollection(K k) { return new ValueSet(this, k, this.valueSetCapacity); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final Set replaceValues(K k, Iterable iterable) { return super.replaceValues((Object) k, (Iterable) iterable); } @Override // com.google.common.collect.AbstractSetMultimap, com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final Set> entries() { return super.entries(); } @Override // com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final Set keySet() { return super.keySet(); } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap, com.google.common.collect.Multimap public final Collection values() { return super.values(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public final class ValueSet extends Sets.ImprovedAbstractSet implements ValueSetLink { ValueEntry[] hashTable; private final K key; final LinkedHashMultimap this$0; private int size = 0; private int modCount = 0; private ValueSetLink firstEntry = this; private ValueSetLink lastEntry = this; ValueSet(LinkedHashMultimap linkedHashMultimap, K k, int i) { this.this$0 = linkedHashMultimap; this.key = k; this.hashTable = new ValueEntry[Hashing.closedTableSize(i, 1.0d)]; } private int mask() { return this.hashTable.length - 1; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public final Iterator iterator() { return new Iterator(this) { // from class: com.google.common.collect.LinkedHashMultimap.ValueSet.1 int expectedModCount; ValueSetLink nextEntry; final ValueSet this$1; ValueEntry toRemove; { this.this$1 = this; this.nextEntry = this.firstEntry; this.expectedModCount = this.modCount; } private void checkForComodification() { if (this.this$1.modCount != this.expectedModCount) { throw new ConcurrentModificationException(); } } @Override // java.util.Iterator public boolean hasNext() { checkForComodification(); return this.nextEntry != this.this$1; } @Override // java.util.Iterator public V next() { if (!hasNext()) { throw new NoSuchElementException(); } ValueEntry valueEntry = (ValueEntry) this.nextEntry; V value = valueEntry.getValue(); this.toRemove = valueEntry; this.nextEntry = valueEntry.getSuccessorInValueSet(); return value; } @Override // java.util.Iterator public void remove() { checkForComodification(); CollectPreconditions.checkRemove(this.toRemove != null); this.this$1.remove(this.toRemove.getValue()); this.expectedModCount = this.this$1.modCount; this.toRemove = null; } }; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean contains(Object obj) { int smearedHash = Hashing.smearedHash(obj); for (ValueEntry valueEntry = this.hashTable[mask() & smearedHash]; valueEntry != null; valueEntry = valueEntry.nextInValueBucket) { if (valueEntry.matchesValue(obj, smearedHash)) { return true; } } return false; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean add(V v) { int smearedHash = Hashing.smearedHash(v); int mask = mask() & smearedHash; ValueEntry valueEntry = this.hashTable[mask]; for (ValueEntry valueEntry2 = valueEntry; valueEntry2 != null; valueEntry2 = valueEntry2.nextInValueBucket) { if (valueEntry2.matchesValue(v, smearedHash)) { return false; } } ValueEntry valueEntry3 = new ValueEntry<>(this.key, v, smearedHash, valueEntry); LinkedHashMultimap.succeedsInValueSet(this.lastEntry, valueEntry3); LinkedHashMultimap.succeedsInValueSet(valueEntry3, this); LinkedHashMultimap.succeedsInMultimap(this.this$0.multimapHeaderEntry.getPredecessorInMultimap(), valueEntry3); LinkedHashMultimap.succeedsInMultimap(valueEntry3, this.this$0.multimapHeaderEntry); this.hashTable[mask] = valueEntry3; this.size++; this.modCount++; rehashIfNecessary(); return true; } private void rehashIfNecessary() { if (Hashing.needsResizing(this.size, this.hashTable.length, 1.0d)) { int length = this.hashTable.length << 1; ValueEntry[] valueEntryArr = new ValueEntry[length]; this.hashTable = valueEntryArr; for (ValueSetLink valueSetLink = this.firstEntry; valueSetLink != this; valueSetLink = valueSetLink.getSuccessorInValueSet()) { ValueEntry valueEntry = (ValueEntry) valueSetLink; int i = valueEntry.smearedValueHash & (length - 1); valueEntry.nextInValueBucket = valueEntryArr[i]; valueEntryArr[i] = valueEntry; } } } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final boolean remove(Object obj) { int smearedHash = Hashing.smearedHash(obj); int mask = mask() & smearedHash; ValueEntry valueEntry = null; for (ValueEntry valueEntry2 = this.hashTable[mask]; valueEntry2 != null; valueEntry2 = valueEntry2.nextInValueBucket) { if (valueEntry2.matchesValue(obj, smearedHash)) { if (valueEntry == null) { this.hashTable[mask] = valueEntry2.nextInValueBucket; } else { valueEntry.nextInValueBucket = valueEntry2.nextInValueBucket; } LinkedHashMultimap.deleteFromValueSet(valueEntry2); LinkedHashMultimap.deleteFromMultimap(valueEntry2); this.size--; this.modCount++; return true; } valueEntry = valueEntry2; } return false; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final void clear() { Arrays.fill(this.hashTable, (Object) null); this.size = 0; for (ValueSetLink valueSetLink = this.firstEntry; valueSetLink != this; valueSetLink = valueSetLink.getSuccessorInValueSet()) { LinkedHashMultimap.deleteFromMultimap((ValueEntry) valueSetLink); } LinkedHashMultimap.succeedsInValueSet(this, this); this.modCount++; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public final int size() { return this.size; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final void setSuccessorInValueSet(ValueSetLink valueSetLink) { this.firstEntry = valueSetLink; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final void setPredecessorInValueSet(ValueSetLink valueSetLink) { this.lastEntry = valueSetLink; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final ValueSetLink getSuccessorInValueSet() { return this.firstEntry; } @Override // com.google.common.collect.LinkedHashMultimap.ValueSetLink public final ValueSetLink getPredecessorInValueSet() { return this.lastEntry; } } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap final Iterator> entryIterator() { return new Iterator>(this) { // from class: com.google.common.collect.LinkedHashMultimap.1 ValueEntry nextEntry; final LinkedHashMultimap this$0; ValueEntry toRemove; { this.this$0 = this; this.nextEntry = this.multimapHeaderEntry.successorInMultimap; } @Override // java.util.Iterator public boolean hasNext() { return this.nextEntry != this.this$0.multimapHeaderEntry; } @Override // java.util.Iterator public Map.Entry next() { if (!hasNext()) { throw new NoSuchElementException(); } ValueEntry valueEntry = this.nextEntry; this.toRemove = valueEntry; this.nextEntry = valueEntry.successorInMultimap; return valueEntry; } @Override // java.util.Iterator public void remove() { CollectPreconditions.checkRemove(this.toRemove != null); this.this$0.remove(this.toRemove.getKey(), this.toRemove.getValue()); this.toRemove = null; } }; } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.AbstractMultimap final Iterator valueIterator() { return Maps.valueIterator(entryIterator()); } @Override // com.google.common.collect.AbstractMapBasedMultimap, com.google.common.collect.Multimap public final void clear() { super.clear(); ValueEntry valueEntry = this.multimapHeaderEntry; succeedsInMultimap(valueEntry, valueEntry); } private void writeObject(ObjectOutputStream objectOutputStream) throws IOException { objectOutputStream.defaultWriteObject(); objectOutputStream.writeInt(keySet().size()); Iterator it = keySet().iterator(); while (it.hasNext()) { objectOutputStream.writeObject(it.next()); } objectOutputStream.writeInt(size()); for (Map.Entry entry : entries()) { objectOutputStream.writeObject(entry.getKey()); objectOutputStream.writeObject(entry.getValue()); } } /* JADX WARN: Multi-variable type inference failed */ private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException { objectInputStream.defaultReadObject(); ValueEntry valueEntry = new ValueEntry<>(null, null, 0, null); this.multimapHeaderEntry = valueEntry; succeedsInMultimap(valueEntry, valueEntry); this.valueSetCapacity = 2; int readInt = objectInputStream.readInt(); Map newLinkedHashMapWithExpectedSize = Platform.newLinkedHashMapWithExpectedSize(12); for (int i = 0; i < readInt; i++) { Object readObject = objectInputStream.readObject(); newLinkedHashMapWithExpectedSize.put(readObject, createCollection(readObject)); } int readInt2 = objectInputStream.readInt(); for (int i2 = 0; i2 < readInt2; i2++) { ((Collection) newLinkedHashMapWithExpectedSize.get(objectInputStream.readObject())).add(objectInputStream.readObject()); } setMap(newLinkedHashMapWithExpectedSize); } }