package com.google.common.collect; import com.google.common.collect.Multiset; import com.google.common.collect.Multisets; import java.util.Comparator; import java.util.Iterator; import java.util.NavigableSet; import java.util.NoSuchElementException; import java.util.SortedSet; /* loaded from: classes2.dex */ final class SortedMultisets { private SortedMultisets() { } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static class ElementSet extends Multisets.ElementSet implements SortedSet { private final SortedMultiset multiset; ElementSet(SortedMultiset sortedMultiset) { this.multiset = sortedMultiset; } @Override // com.google.common.collect.Multisets.ElementSet, java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return Multisets.elementIterator(multiset().entrySet().iterator()); } @Override // java.util.SortedSet public Comparator comparator() { return multiset().comparator(); } @Override // java.util.SortedSet public SortedSet subSet(E e, E e2) { return multiset().subMultiset(e, BoundType.CLOSED, e2, BoundType.OPEN).elementSet(); } @Override // java.util.SortedSet public SortedSet headSet(E e) { return multiset().headMultiset(e, BoundType.OPEN).elementSet(); } @Override // java.util.SortedSet public SortedSet tailSet(E e) { return multiset().tailMultiset(e, BoundType.CLOSED).elementSet(); } @Override // java.util.SortedSet public E first() { return (E) SortedMultisets.getElementOrThrow(multiset().firstEntry()); } @Override // java.util.SortedSet public E last() { return (E) SortedMultisets.getElementOrThrow(multiset().lastEntry()); } /* JADX INFO: Access modifiers changed from: package-private */ @Override // com.google.common.collect.Multisets.ElementSet public final SortedMultiset multiset() { return this.multiset; } } /* loaded from: classes2.dex */ static class NavigableElementSet extends ElementSet implements NavigableSet { /* JADX INFO: Access modifiers changed from: package-private */ public NavigableElementSet(SortedMultiset sortedMultiset) { super(sortedMultiset); } @Override // java.util.NavigableSet public E lower(E e) { return (E) SortedMultisets.getElementOrNull(multiset().headMultiset(e, BoundType.OPEN).lastEntry()); } @Override // java.util.NavigableSet public E floor(E e) { return (E) SortedMultisets.getElementOrNull(multiset().headMultiset(e, BoundType.CLOSED).lastEntry()); } @Override // java.util.NavigableSet public E ceiling(E e) { return (E) SortedMultisets.getElementOrNull(multiset().tailMultiset(e, BoundType.CLOSED).firstEntry()); } @Override // java.util.NavigableSet public E higher(E e) { return (E) SortedMultisets.getElementOrNull(multiset().tailMultiset(e, BoundType.OPEN).firstEntry()); } @Override // java.util.NavigableSet public NavigableSet descendingSet() { return new NavigableElementSet(multiset().descendingMultiset()); } @Override // java.util.NavigableSet public Iterator descendingIterator() { return descendingSet().iterator(); } @Override // java.util.NavigableSet public E pollFirst() { return (E) SortedMultisets.getElementOrNull(multiset().pollFirstEntry()); } @Override // java.util.NavigableSet public E pollLast() { return (E) SortedMultisets.getElementOrNull(multiset().pollLastEntry()); } @Override // java.util.NavigableSet public NavigableSet subSet(E e, boolean z, E e2, boolean z2) { return new NavigableElementSet(multiset().subMultiset(e, BoundType.forBoolean(z), e2, BoundType.forBoolean(z2))); } @Override // java.util.NavigableSet public NavigableSet headSet(E e, boolean z) { return new NavigableElementSet(multiset().headMultiset(e, BoundType.forBoolean(z))); } @Override // java.util.NavigableSet public NavigableSet tailSet(E e, boolean z) { return new NavigableElementSet(multiset().tailMultiset(e, BoundType.forBoolean(z))); } } /* JADX INFO: Access modifiers changed from: private */ public static E getElementOrThrow(Multiset.Entry entry) { if (entry == null) { throw new NoSuchElementException(); } return entry.getElement(); } /* JADX INFO: Access modifiers changed from: private */ public static E getElementOrNull(Multiset.Entry entry) { if (entry == null) { return null; } return entry.getElement(); } }