package com.google.common.collect;

import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.SortedSet;

/* JADX INFO: loaded from: classes2.dex */
public final class p1 extends o1 implements SortedSet {
    @Override // java.util.SortedSet
    public final Comparator comparator() {
        return ((SortedSet) this.f23706a).comparator();
    }

    @Override // java.util.SortedSet
    public final Object first() {
        Iterator it = this.f23706a.iterator();
        it.getClass();
        com.google.common.base.g gVar = this.f23707b;
        gVar.getClass();
        while (it.hasNext()) {
            Object next = it.next();
            if (gVar.apply(next)) {
                return next;
            }
        }
        throw new NoSuchElementException();
    }

    @Override // java.util.SortedSet
    public final SortedSet headSet(Object obj) {
        return new p1(((SortedSet) this.f23706a).headSet(obj), this.f23707b);
    }

    @Override // java.util.SortedSet
    public final Object last() {
        SortedSet sortedSetHeadSet = (SortedSet) this.f23706a;
        while (true) {
            Object objLast = sortedSetHeadSet.last();
            if (this.f23707b.apply(objLast)) {
                return objLast;
            }
            sortedSetHeadSet = sortedSetHeadSet.headSet(objLast);
        }
    }

    @Override // java.util.SortedSet
    public final SortedSet subSet(Object obj, Object obj2) {
        return new p1(((SortedSet) this.f23706a).subSet(obj, obj2), this.f23707b);
    }

    @Override // java.util.SortedSet
    public final SortedSet tailSet(Object obj) {
        return new p1(((SortedSet) this.f23706a).tailSet(obj), this.f23707b);
    }
}
