what-the-bank/sources/org/simpleframework/xml/util/WeakCache.java

133 lines
3.4 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
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<T> implements Cache<T> {
private WeakCache<T>.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<WeakCache<T>.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<T>.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<WeakCache<T>.Segment> {
private List<WeakCache<T>.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<WeakCache<T>.Segment> iterator() {
return this.list.iterator();
}
public WeakCache<T>.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<Object, T> {
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;
}
}
}