ariba.util.core
Class Deque

java.lang.Object
  extended by ariba.util.core.Deque
All Implemented Interfaces:
DebugState

public class Deque
extends java.lang.Object
implements DebugState

This class implements a double-ended queue (pronounced like "deck"). It has the behavior that each operation is in constant (amortized) time. It supports FIFO operation with the enqueue and dequeue methods, and LIFO with push and pop methods. Both access methods may be used on a single deque. This is a similar interface to the deque described in Intorduction to Algorithms by Cormen, Leiserson and Rivest: Eighth printing in chapter 11 (Elementary Data Structures) section 1 (Stacks and queues)


Constructor Summary
Deque()
          Construct a deque with a default capacity.
Deque(int initialCapacity)
          Construct a deque with a given initial capacity.
 
Method Summary
 int count()
          Check the number of elements in the deque.
 java.lang.Object debugState()
          Iterates through the deque from head to tail and calls toString on each node
 java.lang.Object dequeue()
          Dequeues from the deque.
 void enqueue(java.lang.Object o)
          Enqueues an object into the deque.
 boolean isEmpty()
          Check if the deque is empty.
 java.lang.Object peekDequeue()
          Peek in the deque without removing it.
 java.lang.Object peekPop()
          Peek into the deque without removing any elements.
 java.lang.Object pop()
          Pops an element from the deque.
 void push(java.lang.Object o)
          Pushes an object onto the deque in the manner of a stack.
 void setSize(int size)
          Set the size for the internal storage.
 int size()
          Check the number of elements in the deque.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Deque

public Deque()
Construct a deque with a default capacity.


Deque

public Deque(int initialCapacity)
Construct a deque with a given initial capacity.

Parameters:
initialCapacity - the minimum number of elements that the deque is required to hold before having to grow the internal storage.
Method Detail

enqueue

public void enqueue(java.lang.Object o)
Enqueues an object into the deque.

Parameters:
o - the object to enqueue

dequeue

public java.lang.Object dequeue()
Dequeues from the deque.

Returns:
the oldest element in the deque.

peekDequeue

public java.lang.Object peekDequeue()
Peek in the deque without removing it.

Returns:
the oldest element in the deque.

push

public void push(java.lang.Object o)
Pushes an object onto the deque in the manner of a stack. This method is a synonym for enqueue.

Parameters:
o - the object to enqueue
See Also:
enqueue(Object)

peekPop

public java.lang.Object peekPop()
Peek into the deque without removing any elements.

Returns:
the youngest element in the deque

pop

public java.lang.Object pop()
Pops an element from the deque.

Returns:
the youngest element in the deque

setSize

public void setSize(int size)
Set the size for the internal storage. This may be larger or smaller than the current size.

Parameters:
size - the new size for the internal storage. This must be greater than or equal to the count and may not be zero.

count

public int count()
Check the number of elements in the deque.

Returns:
the number of elements in the deque.

size

public int size()
Check the number of elements in the deque.

Returns:
the number of elements in the deque.

isEmpty

public boolean isEmpty()
Check if the deque is empty.

Returns:
true if and only if the deque is empty.

debugState

public java.lang.Object debugState()
Iterates through the deque from head to tail and calls toString on each node

Specified by:
debugState in interface DebugState
Returns:
an object that encapsulates the state of the current application. The toString() method of the returned object should be made safe even if the object that implements DebugState is being modified at the time. Exceptions from toString are tollerable in this case, but data corruption is not.
See Also:
ThreadDebugState.set(ariba.util.core.ThreadDebugKey, java.lang.Object)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


AribaWeb User Interface Development Framework
Copyright © 2000-2014 Ariba, Inc. All Rights Reserved.