package defpackage;

import java.lang.ref.WeakReference;
import java.util.AbstractMap;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/* renamed from: ᵠᵾᵘʿ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3161 implements Set {

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final AtomicLong f11994 = new AtomicLong();

    /* renamed from: ᵢˇᵭ, reason: contains not printable characters */
    public final ReentrantReadWriteLock f11995;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public final /* synthetic */ int f11996;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public final long f11997;

    /* renamed from: ᵾᵬ, reason: contains not printable characters */
    public C0413 f11998;

    /* renamed from: ᵿʗᵝʽ, reason: contains not printable characters */
    public final AbstractMap f11999;

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public C3161() {
        this(new HashMap(), (byte) 0);
        this.f11996 = 0;
    }

    /* JADX WARN: 'this' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C3161(AbstractMap abstractMap) {
        this(abstractMap, (byte) 0);
        this.f11996 = 1;
    }

    public C3161(AbstractMap abstractMap, byte b) {
        this.f11997 = f11994.getAndIncrement();
        this.f11995 = new ReentrantReadWriteLock();
        this.f11999 = abstractMap;
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean add(Object obj) {
        boolean z = false;
        if (obj == null) {
            return false;
        }
        ReentrantReadWriteLock.WriteLock writeLock = this.f11995.writeLock();
        try {
            writeLock.lock();
            AbstractMap abstractMap = this.f11999;
            if (!abstractMap.containsKey(obj)) {
                C0413 c0413M7520 = m7520(obj, this.f11998);
                this.f11998 = c0413M7520;
                abstractMap.put(obj, c0413M7520);
                z = true;
            }
            return z;
        } finally {
            writeLock.unlock();
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean addAll(Collection collection) {
        boolean z;
        ReentrantReadWriteLock.WriteLock writeLock = this.f11995.writeLock();
        try {
            writeLock.lock();
            boolean z2 = false;
            for (Object obj : collection) {
                if (obj != null) {
                    AbstractMap abstractMap = this.f11999;
                    if (abstractMap.containsKey(obj)) {
                        z = false;
                    } else {
                        C0413 c0413M7520 = m7520(obj, this.f11998);
                        this.f11998 = c0413M7520;
                        abstractMap.put(obj, c0413M7520);
                        z = true;
                    }
                    z2 |= z;
                }
            }
            return z2;
        } finally {
            writeLock.unlock();
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final void clear() {
        ReentrantReadWriteLock.WriteLock writeLock = this.f11995.writeLock();
        try {
            writeLock.lock();
            this.f11998 = null;
            this.f11999.clear();
        } finally {
            writeLock.unlock();
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean contains(Object obj) {
        ReentrantReadWriteLock.ReadLock lock = this.f11995.readLock();
        try {
            lock.lock();
            C0413 c0413 = (C0413) this.f11999.get(obj);
            return (c0413 == null || c0413.m1892() == null) ? false : true;
        } finally {
            lock.unlock();
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean containsAll(Collection collection) {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        return obj != null && getClass() == obj.getClass() && this.f11997 == ((C3161) obj).f11997;
    }

    @Override // java.util.Set, java.util.Collection
    public final int hashCode() {
        long j = this.f11997;
        return 31 + ((int) (j ^ (j >>> 32)));
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean isEmpty() {
        return this.f11998 == null;
    }

    @Override // java.util.Set, java.util.Collection, java.lang.Iterable
    public final Iterator iterator() {
        switch (this.f11996) {
            case 0:
                return new C1591(this);
            default:
                return new C1591(this, (byte) 0);
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean remove(Object obj) {
        AbstractMap abstractMap = this.f11999;
        if (!contains(obj)) {
            return false;
        }
        ReentrantReadWriteLock.WriteLock writeLock = this.f11995.writeLock();
        try {
            writeLock.lock();
            C0413 c0413 = (C0413) abstractMap.get(obj);
            if (c0413 == null) {
                return false;
            }
            C0413 c04132 = this.f11998;
            if (c0413 != c04132) {
                C0413 c04133 = c0413.f2311;
                C0413 c04134 = c0413.f2310;
                if (c04133 != null) {
                    c04133.f2310 = c04134;
                    C0413 c04135 = c0413.f2310;
                    if (c04135 != null) {
                        c04135.f2311 = c04133;
                    }
                } else if (c04134 != null) {
                    c04134.f2311 = null;
                }
            } else {
                this.f11998 = c04132.f2310;
            }
            abstractMap.remove(obj);
            writeLock.unlock();
            return true;
        } finally {
            writeLock.unlock();
        }
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean removeAll(Collection collection) {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override // java.util.Set, java.util.Collection
    public final boolean retainAll(Collection collection) {
        throw new UnsupportedOperationException("Not implemented");
    }

    @Override // java.util.Set, java.util.Collection
    public final int size() {
        return this.f11999.size();
    }

    @Override // java.util.Set, java.util.Collection
    public final Object[] toArray() {
        return this.f11999.entrySet().toArray();
    }

    @Override // java.util.Set, java.util.Collection
    public final Object[] toArray(Object[] objArr) {
        return this.f11999.entrySet().toArray(objArr);
    }

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C0413 m7520(Object obj, C0413 c0413) {
        C0413 c04132;
        C0413 c04133;
        switch (this.f11996) {
            case 0:
                if (c0413 != null) {
                    c04132 = new C0413(c0413, 0);
                    c04132.f2312 = obj;
                } else {
                    c04132 = new C0413(0);
                    c04132.f2312 = obj;
                }
                return c04132;
            default:
                if (c0413 != null) {
                    c04133 = new C0413(c0413, 1);
                    c04133.f2312 = new WeakReference(obj);
                } else {
                    c04133 = new C0413(1);
                    c04133.f2312 = new WeakReference(obj);
                }
                return c04133;
        }
    }
}
