package org.simpleframework.xml.util; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.WeakHashMap; /* loaded from: classes6.dex */ public class WeakCache implements Cache { private WeakCache.SegmentList list; public WeakCache() { this(10); } public WeakCache(int i) { this.list = new SegmentList(this, i); } @Override // org.simpleframework.xml.util.Cache public boolean isEmpty() { Iterator.Segment> it = this.list.iterator(); while (it.hasNext()) { if (!it.next().isEmpty()) { return false; } } return true; } @Override // org.simpleframework.xml.util.Cache public void cache(Object obj, T t) { map(obj).cache(obj, t); } @Override // org.simpleframework.xml.util.Cache public T take(Object obj) { return map(obj).take(obj); } @Override // org.simpleframework.xml.util.Cache public T fetch(Object obj) { return map(obj).fetch(obj); } @Override // org.simpleframework.xml.util.Cache public boolean contains(Object obj) { return map(obj).contains(obj); } private WeakCache.Segment map(Object obj) { return this.list.get(obj); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public class SegmentList implements Iterable.Segment> { private List.Segment> list = new ArrayList(); private int size; final WeakCache this$0; public SegmentList(WeakCache weakCache, int i) { this.this$0 = weakCache; this.size = i; create(i); } @Override // java.lang.Iterable public Iterator.Segment> iterator() { return this.list.iterator(); } public WeakCache.Segment get(Object obj) { int segment = segment(obj); if (segment < this.size) { return this.list.get(segment); } return null; } private void create(int i) { while (i > 0) { this.list.add(new Segment()); i--; } } private int segment(Object obj) { return Math.abs(obj.hashCode() % this.size); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public class Segment extends WeakHashMap { final WeakCache this$0; private Segment(WeakCache weakCache) { this.this$0 = weakCache; } public void cache(Object obj, T t) { synchronized (this) { put(obj, t); } } public T fetch(Object obj) { T t; synchronized (this) { t = get(obj); } return t; } public T take(Object obj) { T remove; synchronized (this) { remove = remove(obj); } return remove; } public boolean contains(Object obj) { boolean containsKey; synchronized (this) { containsKey = containsKey(obj); } return containsKey; } } }