Add javadocs to ConcurrentStack

This commit is contained in:
LeoDog896 2021-01-18 10:35:43 -05:00
parent ac68c094ce
commit 83111cb8bb
1 changed files with 14 additions and 0 deletions

View File

@ -16,6 +16,11 @@ public final class ConcurrentStack<E> {
}
/**
* Adds a new element to the top of the stack
*
* @param item The item to add to the top of the stack
*/
public void push(E item) {
Node<E> newHead = new Node<>(item);
Node<E> oldHead;
@ -25,6 +30,11 @@ public final class ConcurrentStack<E> {
} while (!top.compareAndSet(oldHead, newHead));
}
/**
* Removes an element from the top of the stack
*
* @return The removed element.
*/
public E pop() {
Node<E> oldHead;
Node<E> newHead;
@ -37,6 +47,10 @@ public final class ConcurrentStack<E> {
return oldHead.item;
}
public void clear() {
top.set(null);
}
private static class Node<E> {
public final E item;
public Node<E> next;