package org.greenrobot.greendao.query; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import org.greenrobot.greendao.AbstractDao; import org.greenrobot.greendao.query.AbstractQuery; /* loaded from: classes2.dex */ abstract class AbstractQueryData> { final String a; final AbstractDao b; final String[] c; final Map> d = new HashMap(); AbstractQueryData(AbstractDao abstractDao, String str, String[] strArr) { this.b = abstractDao; this.a = str; this.c = strArr; } protected abstract Q a(); Q a(Q q) { if (Thread.currentThread() != q.e) { return b(); } String[] strArr = this.c; System.arraycopy(strArr, 0, q.d, 0, strArr.length); return q; } Q b() { Q q; long id = Thread.currentThread().getId(); synchronized (this.d) { WeakReference weakReference = this.d.get(Long.valueOf(id)); q = weakReference != null ? weakReference.get() : null; if (q == null) { c(); q = a(); this.d.put(Long.valueOf(id), new WeakReference<>(q)); } else { System.arraycopy(this.c, 0, q.d, 0, this.c.length); } } return q; } void c() { synchronized (this.d) { Iterator>> it = this.d.entrySet().iterator(); while (it.hasNext()) { if (it.next().getValue().get() == null) { it.remove(); } } } } }