package androidx.lifecycle;

import java.io.Closeable;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

/* JADX INFO: compiled from: ViewModel.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class z {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private final Map<String, Object> f2599a = new HashMap();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private final Set<Closeable> f2600b = new LinkedHashSet();

    private static void b(Object obj) {
        if (obj instanceof Closeable) {
            try {
                ((Closeable) obj).close();
            } catch (IOException e3) {
                throw new RuntimeException(e3);
            }
        }
    }

    final void a() {
        Map<String, Object> map = this.f2599a;
        if (map != null) {
            synchronized (map) {
                Iterator<Object> it = this.f2599a.values().iterator();
                while (it.hasNext()) {
                    b(it.next());
                }
            }
        }
        Set<Closeable> set = this.f2600b;
        if (set != null) {
            synchronized (set) {
                Iterator<Closeable> it2 = this.f2600b.iterator();
                while (it2.hasNext()) {
                    b(it2.next());
                }
            }
        }
        d();
    }

    <T> T c(String str) {
        T t2;
        Map<String, Object> map = this.f2599a;
        if (map == null) {
            return null;
        }
        synchronized (map) {
            t2 = (T) this.f2599a.get(str);
        }
        return t2;
    }

    protected void d() {
    }
}
