com.carrotsearch.hppc
Class KTypeStack<KType>

java.lang.Object
  extended by com.carrotsearch.hppc.KTypeArrayList<KType>
      extended by com.carrotsearch.hppc.KTypeStack<KType>
All Implemented Interfaces:
KTypeCollection<KType>, KTypeContainer<KType>, KTypeIndexedContainer<KType>, java.lang.Cloneable, java.lang.Iterable<KTypeCursor<KType>>, java.util.RandomAccess

public class KTypeStack<KType>
extends KTypeArrayList<KType>

An extension to ObjectArrayList adding stack-related utility methods. The top of the stack is at the KTypeArrayList.size() - 1 element. A brief comparison of the API against the Java Collections framework:

Java Collections Stack and HPPC ObjectStack, related methods.
java.util.Stack ObjectStack
push push
pop pop, discard
peek peek
removeRange, removeElementAtremoveRange, remove, discard
size size
clear clear, release
+ other methods from ObjectArrayList


Field Summary
 
Fields inherited from class com.carrotsearch.hppc.KTypeArrayList
buffer, DEFAULT_CAPACITY, elementsCount, resizer
 
Constructor Summary
KTypeStack()
          Create with default sizing strategy and initial capacity.
KTypeStack(int initialCapacity)
          Create with default sizing strategy and the given initial capacity.
KTypeStack(int initialCapacity, ArraySizingStrategy resizer)
          Create with a custom buffer resizing strategy.
KTypeStack(KTypeContainer<KType> container)
          Create a stack by pushing all elements of another container to it.
 
Method Summary
 KTypeStack<KType> clone()
          Clone this object.
 void discard()
          Discard the top element from the stack.
 void discard(int count)
          Discard an arbitrary number of elements from the top of the stack.
static
<KType> KTypeStack<KType>
from(KType... elements)
          Create a stack by pushing a variable number of arguments to it.
static
<KType> KTypeStack<KType>
from(KTypeContainer<KType> container)
          Create a stack by pushing all elements of another container to it.
static
<KType> KTypeStack<KType>
newInstance()
          Returns a new object of this class with no need to declare generic type (shortcut instead of using a constructor).
static
<KType> KTypeStack<KType>
newInstanceWithCapacity(int initialCapacity)
          Returns a new object of this list with no need to declare generic type (shortcut instead of using a constructor).
 KType peek()
          Peek at the top element on the stack.
 KType pop()
          Remove the top element from the stack and return it.
 void push(KType... elements)
          Vararg-signature method for pushing elements at the top of the stack.
 void push(KType e1)
          Adds one KType to the stack.
 void push(KType[] elements, int start, int len)
          Add a range of array elements to the stack.
 void push(KType e1, KType e2)
          Adds two KTypes to the stack.
 void push(KType e1, KType e2, KType e3)
          Adds three KTypes to the stack.
 void push(KType e1, KType e2, KType e3, KType e4)
          Adds four KTypes to the stack.
 int pushAll(java.lang.Iterable<? extends KTypeCursor<? extends KType>> iterable)
          Pushes all elements from another iterable to the top of the stack.
 int pushAll(KTypeContainer<? extends KType> container)
          Pushes all elements from another container to the top of the stack.
 int removeAll(KTypeLookupContainer<? extends KType> c)
          Default implementation uses a predicate for removal.
 int retainAll(KTypeLookupContainer<? extends KType> c)
          Default implementation uses a predicate for retaining.
 int retainAll(KTypePredicate<? super KType> predicate)
          Default implementation redirects to KTypeCollection.removeAll(KTypePredicate) and negates the predicate.
 KType[] toArray(java.lang.Class<? super KType> clazz)
          Default implementation of copying to an array.
 java.lang.String toString()
          Convert the contents of this container to a human-friendly string.
 
Methods inherited from class com.carrotsearch.hppc.KTypeArrayList
add, add, add, add, addAll, addAll, clear, contains, ensureBufferSpace, ensureCapacity, equals, forEach, forEach, forEach, forEach, get, hashCode, indexOf, insert, isEmpty, iterator, lastIndexOf, release, remove, removeAll, removeAllOccurrences, removeFirstOccurrence, removeLastOccurrence, removeRange, resize, set, size, toArray, trimToSize
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.carrotsearch.hppc.KTypeCollection
removeAll, retainAll, retainAll
 
Methods inherited from interface com.carrotsearch.hppc.KTypeContainer
toArray
 

Constructor Detail

KTypeStack

public KTypeStack()
Create with default sizing strategy and initial capacity.

See Also:
BoundedProportionalArraySizingStrategy

KTypeStack

public KTypeStack(int initialCapacity)
Create with default sizing strategy and the given initial capacity.

See Also:
BoundedProportionalArraySizingStrategy

KTypeStack

public KTypeStack(int initialCapacity,
                  ArraySizingStrategy resizer)
Create with a custom buffer resizing strategy.


KTypeStack

public KTypeStack(KTypeContainer<KType> container)
Create a stack by pushing all elements of another container to it.

Method Detail

push

public final void push(KType e1)
Adds one KType to the stack.


push

public final void push(KType e1,
                       KType e2)
Adds two KTypes to the stack.


push

public final void push(KType e1,
                       KType e2,
                       KType e3)
Adds three KTypes to the stack.


push

public final void push(KType e1,
                       KType e2,
                       KType e3,
                       KType e4)
Adds four KTypes to the stack.


push

public final void push(KType[] elements,
                       int start,
                       int len)
Add a range of array elements to the stack.


push

public final void push(KType... elements)
Vararg-signature method for pushing elements at the top of the stack.

This method is handy, but costly if used in tight loops (anonymous array passing)


pushAll

public final int pushAll(KTypeContainer<? extends KType> container)
Pushes all elements from another container to the top of the stack.


pushAll

public final int pushAll(java.lang.Iterable<? extends KTypeCursor<? extends KType>> iterable)
Pushes all elements from another iterable to the top of the stack.


discard

public final void discard(int count)
Discard an arbitrary number of elements from the top of the stack.


discard

public final void discard()
Discard the top element from the stack.


pop

public final KType pop()
Remove the top element from the stack and return it.


peek

public final KType peek()
Peek at the top element on the stack.


newInstance

public static <KType> KTypeStack<KType> newInstance()
Returns a new object of this class with no need to declare generic type (shortcut instead of using a constructor).


newInstanceWithCapacity

public static <KType> KTypeStack<KType> newInstanceWithCapacity(int initialCapacity)
Returns a new object of this list with no need to declare generic type (shortcut instead of using a constructor).


from

public static <KType> KTypeStack<KType> from(KType... elements)
Create a stack by pushing a variable number of arguments to it.


from

public static <KType> KTypeStack<KType> from(KTypeContainer<KType> container)
Create a stack by pushing all elements of another container to it.


clone

public KTypeStack<KType> clone()
Clone this object. The returned clone will reuse the same hash function and array resizing strategy.

Overrides:
clone in class KTypeArrayList<KType>

removeAll

public int removeAll(KTypeLookupContainer<? extends KType> c)
Default implementation uses a predicate for removal.

Specified by:
removeAll in interface KTypeCollection<KType>
Returns:
Returns the number of removed elements.

retainAll

public int retainAll(KTypeLookupContainer<? extends KType> c)
Default implementation uses a predicate for retaining.

Specified by:
retainAll in interface KTypeCollection<KType>
Returns:
Returns the number of removed elements.

retainAll

public int retainAll(KTypePredicate<? super KType> predicate)
Default implementation redirects to KTypeCollection.removeAll(KTypePredicate) and negates the predicate.

Specified by:
retainAll in interface KTypeCollection<KType>

toArray

public KType[] toArray(java.lang.Class<? super KType> clazz)
Default implementation of copying to an array.

Specified by:
toArray in interface KTypeContainer<KType>

toString

public java.lang.String toString()
Convert the contents of this container to a human-friendly string.

Overrides:
toString in class java.lang.Object


Copyright © 2011 Carrot Search s.c.. All Rights Reserved.