package com.google.common.collect; import com.google.common.base.Preconditions; import com.google.common.collect.Multiset; import com.google.common.collect.SortedMultisets; import java.util.Comparator; import java.util.Iterator; import java.util.NavigableSet; /* loaded from: classes2.dex */ abstract class AbstractSortedMultiset extends AbstractMultiset implements SortedMultiset { @GwtTransient final Comparator comparator; private transient SortedMultiset descendingMultiset; abstract Iterator> descendingEntryIterator(); AbstractSortedMultiset() { this(Ordering.natural()); } /* JADX INFO: Access modifiers changed from: package-private */ public AbstractSortedMultiset(Comparator comparator) { this.comparator = (Comparator) Preconditions.checkNotNull(comparator); } @Override // com.google.common.collect.AbstractMultiset, com.google.common.collect.Multiset public NavigableSet elementSet() { return (NavigableSet) super.elementSet(); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.AbstractMultiset public NavigableSet createElementSet() { return new SortedMultisets.NavigableElementSet(this); } @Override // com.google.common.collect.SortedMultiset public Multiset.Entry firstEntry() { Iterator> entryIterator = entryIterator(); if (entryIterator.hasNext()) { return entryIterator.next(); } return null; } @Override // com.google.common.collect.SortedMultiset public Multiset.Entry lastEntry() { Iterator> descendingEntryIterator = descendingEntryIterator(); if (descendingEntryIterator.hasNext()) { return descendingEntryIterator.next(); } return null; } @Override // com.google.common.collect.SortedMultiset public Multiset.Entry pollFirstEntry() { Iterator> entryIterator = entryIterator(); if (!entryIterator.hasNext()) { return null; } Multiset.Entry next = entryIterator.next(); Multiset.Entry immutableEntry = Multisets.immutableEntry(next.getElement(), next.getCount()); entryIterator.remove(); return immutableEntry; } @Override // com.google.common.collect.SortedMultiset public Multiset.Entry pollLastEntry() { Iterator> descendingEntryIterator = descendingEntryIterator(); if (!descendingEntryIterator.hasNext()) { return null; } Multiset.Entry next = descendingEntryIterator.next(); Multiset.Entry immutableEntry = Multisets.immutableEntry(next.getElement(), next.getCount()); descendingEntryIterator.remove(); return immutableEntry; } @Override // com.google.common.collect.SortedMultiset public SortedMultiset subMultiset(E e, BoundType boundType, E e2, BoundType boundType2) { Preconditions.checkNotNull(boundType); Preconditions.checkNotNull(boundType2); return tailMultiset(e, boundType).headMultiset(e2, boundType2); } Iterator descendingIterator() { return Multisets.iteratorImpl(descendingMultiset()); } @Override // com.google.common.collect.SortedMultiset public SortedMultiset descendingMultiset() { SortedMultiset sortedMultiset = this.descendingMultiset; if (sortedMultiset != null) { return sortedMultiset; } SortedMultiset createDescendingMultiset = createDescendingMultiset(); this.descendingMultiset = createDescendingMultiset; return createDescendingMultiset; } SortedMultiset createDescendingMultiset() { return new DescendingMultiset(this) { // from class: com.google.common.collect.AbstractSortedMultiset.1DescendingMultisetImpl final AbstractSortedMultiset this$0; { this.this$0 = this; } @Override // com.google.common.collect.DescendingMultiset Iterator> entryIterator() { return this.this$0.descendingEntryIterator(); } @Override // com.google.common.collect.DescendingMultiset, com.google.common.collect.ForwardingCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return this.this$0.descendingIterator(); } @Override // com.google.common.collect.DescendingMultiset SortedMultiset forwardMultiset() { return this.this$0; } }; } @Override // com.google.common.collect.SortedMultiset, com.google.common.collect.SortedIterable public Comparator comparator() { return this.comparator; } }