mirror of
https://github.com/corda/corda.git
synced 2025-06-13 12:48:18 +00:00
Added an implemention of ArrayDeque, as well as unit tests
I also used this opportunity to reduce code duplication around other queue/deque implementations.
This commit is contained in:
@ -1,13 +1,12 @@
|
||||
package java.util.concurrent;
|
||||
|
||||
import java.util.AbstractQueue;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Queue;
|
||||
|
||||
import avian.Atomic;
|
||||
|
||||
public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
public class ConcurrentLinkedQueue<T> extends AbstractQueue<T> {
|
||||
private static final long QueueHead;
|
||||
private static final long QueueTail;
|
||||
private static final long NodeNext;
|
||||
@ -67,31 +66,11 @@ public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
return poll(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T element() {
|
||||
T result = peek();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T poll() {
|
||||
return poll(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T remove() {
|
||||
T result = poll();
|
||||
if (result == null) {
|
||||
throw new NoSuchElementException();
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private T poll(boolean remove) {
|
||||
while (true) {
|
||||
Node<T> h = head;
|
||||
@ -150,12 +129,6 @@ public class ConcurrentLinkedQueue<T> implements Queue<T> {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean addAll(Collection<? extends T> collection) {
|
||||
// TODO - implement
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Object element) {
|
||||
// TODO - implement
|
||||
|
Reference in New Issue
Block a user