what-the-bank/sources/com/google/common/collect/EvictingQueue.java

73 lines
2.4 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Preconditions;
import java.io.Serializable;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Queue;
/* loaded from: classes2.dex */
public final class EvictingQueue<E> extends ForwardingQueue<E> implements Serializable {
private static final long serialVersionUID = 0;
private final Queue<E> delegate;
final int maxSize;
private EvictingQueue(int i) {
Preconditions.checkArgument(i >= 0, "maxSize (%s) must >= 0", i);
this.delegate = new ArrayDeque(i);
this.maxSize = i;
}
public static <E> EvictingQueue<E> create(int i) {
return new EvictingQueue<>(i);
}
public final int remainingCapacity() {
return this.maxSize - size();
}
@Override // com.google.common.collect.ForwardingQueue, java.util.Queue
public final boolean offer(E e) {
return add(e);
}
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Queue
public final boolean add(E e) {
Preconditions.checkNotNull(e);
if (this.maxSize == 0) {
return true;
}
if (size() == this.maxSize) {
this.delegate.remove();
}
this.delegate.add(e);
return true;
}
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection
public final boolean addAll(Collection<? extends E> collection) {
int size = collection.size();
if (size >= this.maxSize) {
clear();
return Iterables.addAll(this, Iterables.skip(collection, size - this.maxSize));
}
return standardAddAll(collection);
}
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set
public final boolean contains(Object obj) {
return delegate().contains(Preconditions.checkNotNull(obj));
}
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set
public final boolean remove(Object obj) {
return delegate().remove(Preconditions.checkNotNull(obj));
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.ForwardingQueue, com.google.common.collect.ForwardingCollection, com.google.common.collect.ForwardingObject
public final Queue<E> delegate() {
return this.delegate;
}
}