Renaming peek() to peekNode and making it protected, then creating a new peek that returns T
This commit is contained in:
parent
cb5c17dd7f
commit
c48a2c4aac
1 changed files with 8 additions and 3 deletions
|
|
@ -22,10 +22,15 @@ public abstract class AbstractNodeQueue<T> extends AtomicReference<AbstractNodeQ
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final Node<T> peek() {
|
protected final Node<T> peekNode() {
|
||||||
return ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)).next();
|
return ((Node<T>)Unsafe.instance.getObjectVolatile(this, tailOffset)).next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final T peek() {
|
||||||
|
final Node<T> n = peekNode();
|
||||||
|
return (n != null) ? n.value : null;
|
||||||
|
}
|
||||||
|
|
||||||
public final void add(final T value) {
|
public final void add(final T value) {
|
||||||
final Node<T> n = new Node<T>(value);
|
final Node<T> n = new Node<T>(value);
|
||||||
getAndSet(n).setNext(n);
|
getAndSet(n).setNext(n);
|
||||||
|
|
@ -37,14 +42,14 @@ public abstract class AbstractNodeQueue<T> extends AtomicReference<AbstractNodeQ
|
||||||
|
|
||||||
public final int count() {
|
public final int count() {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
for(Node<T> n = peek();n != null; n = n.next())
|
for(Node<T> n = peekNode();n != null; n = n.next())
|
||||||
++count;
|
++count;
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public final T poll() {
|
public final T poll() {
|
||||||
final Node<T> next = peek();
|
final Node<T> next = peekNode();
|
||||||
if (next == null) return null;
|
if (next == null) return null;
|
||||||
else {
|
else {
|
||||||
final T ret = next.value;
|
final T ret = next.value;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue