All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.objectspace.jgl.Deque

java.lang.Object
   |
   +----COM.objectspace.jgl.Deque

public class Deque
extends Object
implements Sequence
A Deque is a sequential container that is optimized for fast indexed-based access and efficient insertion at either of its extremities.

Deques are useful in circumstances where order, compact storage, and fast insertion at extremeties is important. A Deque is ideal for implementing any kind of FIFO structure. If a strict FIFO structure is required that does not allow index-based access, then you should consider using a Queue adaptor with a Deque as the underlying container. If you require very fast insertion near the middle of a sequential structure, then consider using a List instead of a Deque.

The implementation allocates storage for a Deque's elements in 4K blocks (a usual page size) of contiguous memory, and use an array to keep track of a deque's blocks. When a Deque is constructed, it has no associated storage. As elements are added, blocks of storage are added to the beginning or the end of the deque as necessary. A result of this architecture is that items may be inserted very efficiently near either extremity. Once a block has been allocated to a Deque, it is not deallocated until the Deque is destroyed. Insertions are careful to expand the Deque in the direction that involves the least amount of copying. Removals take similar precautions.

If an insertion causes reallocation, all iterators and references are invalidated; otherwise, iterators and references are only invalidated if an item is not inserted at an extremity. In the worst cast, inserting a single element into a Deque takes linear time in the minimum of the distance from the insertion point to the beginning of the Deque and the distance from the insertion point to the end of the Deque. Inserting a single element either at the beginning or end of a Deque always takes constant time.

If the first or last item is removed, all iterators and references remain valid; if any other item is removed, all iterators and references are invalidated.

See Also:
Sequence, DequeExamples

Constructor Index

 o Deque()
Construct myself to be an empty Deque.
 o Deque(Deque)
Construct myself to be a shallow copy of an existing Deque.
 o Deque(int)
Construct myself to contain a specified number of null elements.
 o Deque(int, Object)
Construct myself to contain a specified number of elements set to a particular object.

Method Index

 o add(Object)
Add an object after my last element and return null.
 o at(int)
Return the element at the specified index.
 o back()
Return my last item.
 o begin()
Return an iterator positioned at my first item.
 o clear()
Remove all of my elements.
 o clone()
Return a shallow copy of myself.
 o contains(Object)
Return true if I contain a particular object.
 o copy(Deque)
Become a shallow copy of an existing Deque.
 o count(int, int, Object)
Return the number of objects within a particular range of indices that match a particular value.
 o count(Object)
Return the number of objects that match a particular value.
 o elements()
Return an Enumeration of my components
 o end()
Return an iterator positioned immediately after my last item.
 o equals(Deque)
Return true if I contain the same items in the same order as another Deque.
 o equals(Object)
Return true if I'm equal to another object.
 o finish()
Return an iterator positioned immediately afer my last item.
 o front()
Return my first item.
 o hashCode()
Return my hash code for support of hashing containers
 o indexOf(int, int, Object)
Return the index of the first object within a range of indices that match a particular object, or -1 if the object is not found.
 o indexOf(Object)
Return the index of the first object that matches a particular value, or -1 if the object is not found.
 o insert(DequeIterator, BidirectionalIterator, BidirectionalIterator)
Insert a sequence of objects at a particular location.
 o insert(DequeIterator, int, Object)
Insert multiple objects at a particular position.
 o insert(DequeIterator, Object)
Insert an object at a particular position and return an iterator positioned at the new element.
 o insert(int, BidirectionalIterator, BidirectionalIterator)
Insert a sequence of objects at a particular index.
 o insert(int, int, Object)
Insert multiple objects at a particular index.
 o insert(int, Object)
Insert an object at a particular index and return an iterator positioned at the new element.
 o isEmpty()
Return true if I contain no entries.
 o maxSize()
Return the maximum number of entries that I can contain.
 o popBack()
Remove and return my last element.
 o popFront()
Remove and return my first element.
 o pushBack(Object)
Add an object after my last element.
 o pushFront(Object)
Insert an object in front of my first element.
 o put(int, Object)
Set the element at the specified index to a particular object.
 o remove(Enumeration)
Remove the element at a particular position.
 o remove(Enumeration, Enumeration)
Remove the elements in the range [ first..last ).
 o remove(int)
Remove the element at a particular index.
 o remove(int, int)
Remove the elements within a range of indices.
 o remove(int, int, Object)
Remove all elements within a range of indices that match a particular object and return the number of objects that were removed.
 o remove(Object)
Remove all elements that match a particular object and return the numbers of objects that were removed.
 o remove(Object, int)
Remove at most a given number of elements that match a particular object and return the number of objects that were removed.
 o replace(int, int, Object, Object)
Replace all elements within a range of indices that match a particular object with a new value and return the number of objects that were replaced.
 o replace(Object, Object)
Replace all elements that match a particular object with a new value and return the number of objects that were replaced.
 o size()
Return the number of entries that I contain.
 o start()
Return an iterator positioned at my first item
 o swap(Deque)
Swap my contents with another Deque.
 o toString()
Return a string that describes me.

Constructors

 o Deque
 public Deque()
Construct myself to be an empty Deque.

 o Deque
 public Deque(int size)
Construct myself to contain a specified number of null elements.

Parameters:
size - The number of elements to contain.
Throws: IllegalArgumentException
If size is negative.
 o Deque
 public Deque(int size,
              Object object)
Construct myself to contain a specified number of elements set to a particular object.

Parameters:
size - The number of elements to contain.
object - The initial value of each element.
Throws: IllegalArgumentException
If size is negative.
 o Deque
 public Deque(Deque deque)
Construct myself to be a shallow copy of an existing Deque.

Parameters:
deque - The Deque to copy.

Methods

 o clone
 public synchronized Object clone()
Return a shallow copy of myself.

Overrides:
clone in class Object
 o equals
 public boolean equals(Object object)
Return true if I'm equal to another object.

Parameters:
object - The object to compare myself against.
Overrides:
equals in class Object
 o equals
 public synchronized boolean equals(Deque deque)
Return true if I contain the same items in the same order as another Deque. Use equals() to compare the individual elements.

Parameters:
deque - The Deque to compare myself against.
 o hashCode
 public synchronized int hashCode()
Return my hash code for support of hashing containers

Overrides:
hashCode in class Object
 o toString
 public synchronized String toString()
Return a string that describes me.

Overrides:
toString in class Object
 o copy
 public synchronized void copy(Deque deque)
Become a shallow copy of an existing Deque.

Parameters:
deque - The Deque that I shall become a shallow copy of.
 o isEmpty
 public boolean isEmpty()
Return true if I contain no entries.

 o size
 public int size()
Return the number of entries that I contain.

 o maxSize
 public int maxSize()
Return the maximum number of entries that I can contain.

 o add
 public synchronized Object add(Object object)
Add an object after my last element and return null. This function is a synonym for pushBack().

Parameters:
object - The object to add.
 o pushBack
 public void pushBack(Object object)
Add an object after my last element.

Parameters:
The - object to add.
 o pushFront
 public synchronized void pushFront(Object object)
Insert an object in front of my first element.

Parameters:
object - The object to insert.
 o popFront
 public synchronized Object popFront()
Remove and return my first element.

Throws: InvalidOperationException
If the Deque is empty.
 o popBack
 public synchronized Object popBack()
Remove and return my last element.

Throws: InvalidOperationException
If the Deque is empty.
 o clear
 public synchronized void clear()
Remove all of my elements.

 o elements
 public synchronized Enumeration elements()
Return an Enumeration of my components

 o begin
 public synchronized DequeIterator begin()
Return an iterator positioned at my first item.

 o end
 public synchronized DequeIterator end()
Return an iterator positioned immediately after my last item.

 o start
 public ForwardIterator start()
Return an iterator positioned at my first item

 o finish
 public ForwardIterator finish()
Return an iterator positioned immediately afer my last item.

 o front
 public synchronized Object front()
Return my first item.

Throws: InvalidOperationException
If the Deque is empty.
 o back
 public synchronized Object back()
Return my last item.

Throws: InvalidOperationException
If the Deque is empty.
 o at
 public synchronized Object at(int index)
Return the element at the specified index.

Parameters:
index - The index.
Throws: IndexOutOfBoundsException
If the index is invalid.
 o put
 public synchronized void put(int index,
                              Object object)
Set the element at the specified index to a particular object.

Parameters:
index - The index.
object - The object.
Throws: IndexOutOfBoundsException
If the index is invalid.
 o swap
 public synchronized void swap(Deque deque)
Swap my contents with another Deque.

Parameters:
deque - The Deque that I will swap my contents with.
 o remove
 public synchronized Object remove(int index)
Remove the element at a particular index.

Parameters:
index - The index of the element to remove.
Returns:
The object removed.
Throws: IndexOutOfBoundsException
If the index is invalid.
 o remove
 public synchronized Object remove(Enumeration e)
Remove the element at a particular position.

Parameters:
e - An Enumeration positioned at the element to remove.
Returns:
The object removed.
Throws: IllegalArgumentException
if the Enumeration isn't a DequeIterator for this Deque object.
 o remove
 public synchronized int remove(int first,
                                int last)
Remove the elements within a range of indices.

Parameters:
first - The index of the first element to remove.
last - The index of the last element to remove.
Returns:
The number of elements removed.
Throws: IndexOutOfBoundsException
If either index is invalid.
 o remove
 public synchronized int remove(Enumeration first,
                                Enumeration last)
Remove the elements in the range [ first..last ).

Parameters:
first - An Enumeration positioned at the first element to remove.
last - An Enumeration positioned immediately after the last element to remove.
Returns:
The number of elements removed.
Throws: IllegalArgumentException
if the Enumeration isn't a DequeIterator for this Deque object.
 o insert
 public synchronized DequeIterator insert(int index,
                                          Object object)
Insert an object at a particular index and return an iterator positioned at the new element.

Parameters:
index - The index of the element that the object will be inserted immediately before.
object - The object to insert.
Throws: IndexOutOfBoundsException
If the index is invalid.
 o insert
 public synchronized DequeIterator insert(DequeIterator pos,
                                          Object value)
Insert an object at a particular position and return an iterator positioned at the new element.

Parameters:
pos - An iterator positioned at the element that the object will be inserted immediately before.
object - The object to insert.
 o insert
 public synchronized void insert(int index,
                                 int n,
                                 Object value)
Insert multiple objects at a particular index.

Parameters:
index - The index of the element that the objects will be inserted immediately before.
object - The object to insert.
Throws: IndexOutOfBoundsException
If the index is invalid.
Throws: IllegalArgumentException
If the number of objects to insert is negative.
 o insert
 public synchronized void insert(DequeIterator pos,
                                 int n,
                                 Object value)
Insert multiple objects at a particular position.

Parameters:
pos - An iterator positioned at the element that the objects will be inserted immediately before.
n - The number of objects to insert.
object - The object to insert.
Throws: IllegalArgumentException
If the number of objects to insert is negative.
 o insert
 public synchronized void insert(int index,
                                 BidirectionalIterator first,
                                 BidirectionalIterator last)
Insert a sequence of objects at a particular index.

Parameters:
pos - The index of the element that the objects will be inserted immediately before.
first - An iterator positioned at the first element to insert.
last - An iterator positioned immediately after the last element to insert.
Throws: IndexOutOfBoundsException
If the index is invalid.
 o insert
 public synchronized void insert(DequeIterator pos,
                                 BidirectionalIterator first,
                                 BidirectionalIterator last)
Insert a sequence of objects at a particular location.

Parameters:
pos - The location of the element that the objects will be inserted immediately before.
first - An iterator positioned at the first element to insert.
last - An iterator positioned immediately after the last element to insert.
 o remove
 public int remove(Object object)
Remove all elements that match a particular object and return the numbers of objects that were removed.

Parameters:
object - The object to remove.
Returns:
The number of objects removed.
 o remove
 public synchronized int remove(Object object,
                                int count)
Remove at most a given number of elements that match a particular object and return the number of objects that were removed.

Parameters:
object - The object to remove.
count - The maximum number of objects to remove.
Returns:
The number of objects removed.
 o remove
 public synchronized int remove(int first,
                                int last,
                                Object object)
Remove all elements within a range of indices that match a particular object and return the number of objects that were removed.

Parameters:
first - The index of the first object to consider.
last - The index of the last object to consider.
object - The object to remove.
Returns:
The number of objects removed.
Throws: IndexOutOfBoundsException
If either index is invalid.
 o replace
 public synchronized int replace(Object oldValue,
                                 Object newValue)
Replace all elements that match a particular object with a new value and return the number of objects that were replaced.

Parameters:
oldValue - The object to be replaced.
newValue - The value to substitute.
 o replace
 public synchronized int replace(int first,
                                 int last,
                                 Object oldValue,
                                 Object newValue)
Replace all elements within a range of indices that match a particular object with a new value and return the number of objects that were replaced.

Parameters:
first - The index of the first object to be considered.
last - The index of the last object to be considered.
oldValue - The object to be replaced.
newValue - The value to substitute.
Throws: IndexOutOfBoundsException
If either index is invalid.
 o count
 public int count(Object object)
Return the number of objects that match a particular value.

Parameters:
object - The object to count.
 o count
 public synchronized int count(int first,
                               int last,
                               Object object)
Return the number of objects within a particular range of indices that match a particular value.

Parameters:
first - The index of the first object to consider.
last - The index of the last object to consider.
Throws: IndexOutOfBoundsException
If either index is invalid.
 o indexOf
 public int indexOf(Object object)
Return the index of the first object that matches a particular value, or -1 if the object is not found.

Parameters:
object - The object to find.
 o indexOf
 public int indexOf(int first,
                    int last,
                    Object object)
Return the index of the first object within a range of indices that match a particular object, or -1 if the object is not found.

Parameters:
first - The index of the first object to consider.
last - The index of the last object to consider.
object - The object to find.
Throws: IndexOutOfBoundsException
If either index is invalid.
 o contains
 public boolean contains(Object object)
Return true if I contain a particular object.

Parameters:
object - The object in question.

All Packages  Class Hierarchy  This Package  Previous  Next  Index