what-the-bank/sources/com/google/common/collect/SortedMultisets.java

146 lines
5.1 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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<E> extends Multisets.ElementSet<E> implements SortedSet<E> {
private final SortedMultiset<E> multiset;
ElementSet(SortedMultiset<E> 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<E> iterator() {
return Multisets.elementIterator(multiset().entrySet().iterator());
}
@Override // java.util.SortedSet
public Comparator<? super E> comparator() {
return multiset().comparator();
}
@Override // java.util.SortedSet
public SortedSet<E> subSet(E e, E e2) {
return multiset().subMultiset(e, BoundType.CLOSED, e2, BoundType.OPEN).elementSet();
}
@Override // java.util.SortedSet
public SortedSet<E> headSet(E e) {
return multiset().headMultiset(e, BoundType.OPEN).elementSet();
}
@Override // java.util.SortedSet
public SortedSet<E> 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<E> multiset() {
return this.multiset;
}
}
/* loaded from: classes2.dex */
static class NavigableElementSet<E> extends ElementSet<E> implements NavigableSet<E> {
/* JADX INFO: Access modifiers changed from: package-private */
public NavigableElementSet(SortedMultiset<E> 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<E> descendingSet() {
return new NavigableElementSet(multiset().descendingMultiset());
}
@Override // java.util.NavigableSet
public Iterator<E> 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<E> 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<E> headSet(E e, boolean z) {
return new NavigableElementSet(multiset().headMultiset(e, BoundType.forBoolean(z)));
}
@Override // java.util.NavigableSet
public NavigableSet<E> tailSet(E e, boolean z) {
return new NavigableElementSet(multiset().tailMultiset(e, BoundType.forBoolean(z)));
}
}
/* JADX INFO: Access modifiers changed from: private */
public static <E> E getElementOrThrow(Multiset.Entry<E> entry) {
if (entry == null) {
throw new NoSuchElementException();
}
return entry.getElement();
}
/* JADX INFO: Access modifiers changed from: private */
public static <E> E getElementOrNull(Multiset.Entry<E> entry) {
if (entry == null) {
return null;
}
return entry.getElement();
}
}