Package com.helger.commons.collection
Class NonBlockingStack<ELEMENTTYPE>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- java.util.ArrayList<ELEMENTTYPE>
-
- com.helger.commons.collection.impl.CommonsArrayList<ELEMENTTYPE>
-
- com.helger.commons.collection.NonBlockingStack<ELEMENTTYPE>
-
- Type Parameters:
ELEMENTTYPE- The type of the elements contained in the stack
- All Implemented Interfaces:
ICommonsCollection<ELEMENTTYPE>,ICommonsIterable<ELEMENTTYPE>,ICommonsList<ELEMENTTYPE>,ICloneable<ICommonsList<ELEMENTTYPE>>,IHasSize,Serializable,Cloneable,Iterable<ELEMENTTYPE>,Collection<ELEMENTTYPE>,List<ELEMENTTYPE>,RandomAccess
@NotThreadSafe public class NonBlockingStack<ELEMENTTYPE> extends CommonsArrayList<ELEMENTTYPE>
A version of a stack that does not useVectorbut anCommonsArrayListas the underlying data structure as opposed toStack. This spares us from unnecessary synchronization.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description NonBlockingStack()NonBlockingStack(int nInitialCapacity)NonBlockingStack(NonBlockingStack<? extends ELEMENTTYPE> aStack)NonBlockingStack(ELEMENTTYPE... aElements)NonBlockingStack(Collection<? extends ELEMENTTYPE> aCollection)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)ELEMENTTYPEfirstElement()NonBlockingStack<ELEMENTTYPE>getClone()inthashCode()ELEMENTTYPEpeek()Looks at the object at the top of this stack without removing it from the stack.ELEMENTTYPEpop()Removes the object at the top of this stack and returns that object as the value of this function.ELEMENTTYPEpush(ELEMENTTYPE aItem)Pushes an item onto the top of this stack.ELEMENTTYPEreplaceTopElement(ELEMENTTYPE aItem)Replaces the top element in the stack.ELEMENTTYPEtop()Looks at the object at the top of this stack without removing it from the stack.StringtoString()-
Methods inherited from class com.helger.commons.collection.impl.CommonsArrayList
createFiltered, createFiltered, createFiltered, createFiltered, createFiltered, createFiltered, createInstance
-
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, clear, clone, contains, ensureCapacity, forEach, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeIf, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
-
Methods inherited from class java.util.AbstractCollection
containsAll
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsCollection
addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAll, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addAllMapped, addIf, addIfNotNull, addObject, getAtIndex, getAtIndex, getAtIndex, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getAtIndexMapped, getCopyAsList, getCount, getSorted, iterator2, removeAll, removeObject, set, setAll, setAll, setAllMapped, setAllMapped
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsIterable
containsAny, containsNone, containsOnly, findAll, findAllInstanceOf, findAllMapped, findAllMapped, findAllMapped, findFirst, findFirst, findFirstIndex, findFirstMapped, findFirstMapped, findLastIndex, forEachBreakable, forEachByIndex, forEachThrowing, getCount
-
Methods inherited from interface com.helger.commons.collection.impl.ICommonsList
getAll, getAllInstanceOf, getAllMapped, getAllMapped, getAsUnmodifiable, getAtIndex, getFirst, getFirst, getLast, getLast, getSortedInline, removeAndReturnElementAtIndex, removeAtIndex, removeFirst, removeLast, reverse, setFirst, setLast, swapItems
-
Methods inherited from interface com.helger.commons.lang.IHasSize
isEmpty, isNotEmpty, size
-
Methods inherited from interface java.util.List
add, add, addAll, addAll, clear, contains, containsAll, get, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray
-
-
-
-
Constructor Detail
-
NonBlockingStack
public NonBlockingStack()
-
NonBlockingStack
public NonBlockingStack(@Nonnegative int nInitialCapacity)
-
NonBlockingStack
@SafeVarargs public NonBlockingStack(@Nullable ELEMENTTYPE... aElements)
-
NonBlockingStack
public NonBlockingStack(@Nullable Collection<? extends ELEMENTTYPE> aCollection)
-
NonBlockingStack
public NonBlockingStack(@Nullable NonBlockingStack<? extends ELEMENTTYPE> aStack)
-
-
Method Detail
-
push
@Nullable public ELEMENTTYPE push(@Nullable ELEMENTTYPE aItem)
Pushes an item onto the top of this stack.- Parameters:
aItem- the item to be pushed onto this stack.- Returns:
- the
aItemargument.
-
pop
@Nullable public ELEMENTTYPE pop()
Removes the object at the top of this stack and returns that object as the value of this function.- Returns:
- The object at the top of this stack (the last item of the list).
- Throws:
EmptyStackException- if this stack is empty.
-
peek
@Nullable public ELEMENTTYPE peek()
Looks at the object at the top of this stack without removing it from the stack.- Returns:
- the object at the top of this stack (the last item of the list).
- Throws:
EmptyStackException- if this stack is empty.
-
top
@Nullable public ELEMENTTYPE top()
Looks at the object at the top of this stack without removing it from the stack. Synonym forpeek()- Returns:
- the object at the top of this stack (the last item of the list).
- Throws:
EmptyStackException- if this stack is empty.- See Also:
peek()
-
firstElement
@Nullable public ELEMENTTYPE firstElement()
- Returns:
- The first element in the stack (the oldest element) in comparison
to
peek()delivering the last element. - Throws:
EmptyStackException- if the stack is empty
-
replaceTopElement
@Nullable public ELEMENTTYPE replaceTopElement(@Nullable ELEMENTTYPE aItem)
Replaces the top element in the stack. This is a shortcut forpop (); push (aItem);- Parameters:
aItem- the item to be pushed onto this stack.- Returns:
- the
aItemargument. - Throws:
EmptyStackException- if the stack is empty
-
getClone
@Nonnull public NonBlockingStack<ELEMENTTYPE> getClone()
- Specified by:
getClonein interfaceICloneable<ELEMENTTYPE>- Overrides:
getClonein classCommonsArrayList<ELEMENTTYPE>- Returns:
- A 100% deep-copy of the implementing class.
-
equals
public boolean equals(Object o)
- Specified by:
equalsin interfaceCollection<ELEMENTTYPE>- Specified by:
equalsin interfaceList<ELEMENTTYPE>- Overrides:
equalsin classArrayList<ELEMENTTYPE>
-
hashCode
public int hashCode()
- Specified by:
hashCodein interfaceCollection<ELEMENTTYPE>- Specified by:
hashCodein interfaceList<ELEMENTTYPE>- Overrides:
hashCodein classArrayList<ELEMENTTYPE>
-
toString
public String toString()
- Overrides:
toStringin classAbstractCollection<ELEMENTTYPE>
-
-