Initial commit
This commit is contained in:
76
sources/com/google/common/collect/EvictingQueue.java
Normal file
76
sources/com/google/common/collect/EvictingQueue.java
Normal file
@@ -0,0 +1,76 @@
|
||||
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: classes.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.a(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);
|
||||
}
|
||||
|
||||
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Queue
|
||||
public boolean add(E e) {
|
||||
Preconditions.a(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 boolean addAll(Collection<? extends E> collection) {
|
||||
int size = collection.size();
|
||||
if (size < this.maxSize) {
|
||||
return standardAddAll(collection);
|
||||
}
|
||||
clear();
|
||||
return Iterables.a((Collection) this, Iterables.a(collection, size - this.maxSize));
|
||||
}
|
||||
|
||||
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set
|
||||
public boolean contains(Object obj) {
|
||||
Queue<E> delegate = delegate();
|
||||
Preconditions.a(obj);
|
||||
return delegate.contains(obj);
|
||||
}
|
||||
|
||||
@Override // com.google.common.collect.ForwardingQueue, java.util.Queue
|
||||
public boolean offer(E e) {
|
||||
return add(e);
|
||||
}
|
||||
|
||||
public int remainingCapacity() {
|
||||
return this.maxSize - size();
|
||||
}
|
||||
|
||||
@Override // com.google.common.collect.ForwardingCollection, java.util.Collection, java.util.Set
|
||||
public boolean remove(Object obj) {
|
||||
Queue<E> delegate = delegate();
|
||||
Preconditions.a(obj);
|
||||
return delegate.remove(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 Queue<E> delegate() {
|
||||
return this.delegate;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user