Top Description Fields Constructors Methods
org.mortbay.util

public Class ArrayQueue<E>

extends AbstractList<E>
implements Queue<E>
Class Inheritance
All Implemented Interfaces
java.util.Queue, java.util.Collection, java.lang.Iterable
Imports
java.util.AbstractList, .Collection, .Iterator, .List, .NoSuchElementException, .Queue

Queue backed by circular array. This partial Queue implementation (also with pop() for stack operation) is backed by a growable circular array.
Author
gregw

Field Summary

Modifier and TypeField and Description
private Object[]
private int
private Object
private int
private int
private int
public final int
public final int
Inherited from java.util.AbstractList:
modCount

Constructor Summary

AccessConstructor and Description
public
public
ArrayQueue(int capacity)

public
ArrayQueue(int initCapacity, int growBy)

public
ArrayQueue(int initCapacity, int growBy, Object lock)

Method Summary

Modifier and TypeMethod and Description
public boolean
add(E
the element to add
e
)

Overrides java.util.AbstractList.add.

Implements java.util.Queue.add, java.util.List.add, java.util.Collection.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.
public void
add(int
index at which the specified element is to be inserted
index
,
E
element to be inserted
element
)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Inserts the specified element at the specified position in this list (optional operation).
public void
addUnsafe(E e)

add without synchronization or bounds checking

public void
clear()

Overrides java.util.AbstractList.clear.

Implements java.util.Collection.clear, java.util.List.clear.

Removes all of the elements from this collection (optional operation).
public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.
public E
get(int
index of the element to return
index
)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Returns the element at the specified position in this list.
public int
public E
getUnsafe(int index)

Get without synchronization or bounds checking.

protected void
grow()

public boolean
isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty, java.util.List.isEmpty.

Returns true if this collection contains no elements.
public boolean
offer(E
the element to add
e
)

Implements java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
public E
peek()

Implements java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
public E
poll()

Implements java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.
public E
remove()

Implements java.util.Queue.remove.

Retrieves and removes the head of this queue.
public E
remove(int
the index of the element to be removed
index
)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Removes the element at the specified position in this list (optional operation).
public E
set(int
index of the element to replace
index
,
E
element to be stored at the specified position
element
)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Replaces the element at the specified position in this list with the specified element (optional operation).
public int
size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size, java.util.List.size.

Returns the number of elements in this collection.
Inherited from java.util.AbstractList:
addAllequalshashCodeindexOfiteratorlastIndexOflistIteratorlistIteratorremoveRangesubList

Field Detail

_elementsback to summary
private Object[] _elements
_growCapacityback to summary
private int _growCapacity
_lockback to summary
private Object _lock
_nextEback to summary
private int _nextE
_nextSlotback to summary
private int _nextSlot
_sizeback to summary
private int _size
DEFAULT_CAPACITYback to summary
public final int DEFAULT_CAPACITY
DEFAULT_GROWTHback to summary
public final int DEFAULT_GROWTH

Constructor Detail

ArrayQueueback to summary
public ArrayQueue()
ArrayQueueback to summary
public ArrayQueue(int capacity)
ArrayQueueback to summary
public ArrayQueue(int initCapacity, int growBy)
ArrayQueueback to summary
public ArrayQueue(int initCapacity, int growBy, Object lock)

Method Detail

addback to summary
public boolean add(E e)

Overrides java.util.AbstractList.add.

Implements java.util.Queue.add, java.util.List.add, java.util.Collection.add.

Doc from java.util.Queue.add.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Parameters
e:E

the element to add

Returns:boolean

true (as specified by Collection#add)

addback to summary
public void add(int index, E element)

Overrides java.util.AbstractList.add.

Implements java.util.List.add.

Doc from java.util.AbstractList.add.

Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters
index:int

Doc from java.util.List.add.

index at which the specified element is to be inserted

element:E

Doc from java.util.List.add.

element to be inserted

addUnsafeback to summary
public void addUnsafe(E e)

add without synchronization or bounds checking

See Also
add(Object)
clearback to summary
public void clear()

Overrides java.util.AbstractList.clear.

Implements java.util.Collection.clear, java.util.List.clear.

Doc from java.util.Collection.clear.

Removes all of the elements from this collection (optional operation). The collection will be empty after this method returns.

elementback to summary
public E element()

Implements java.util.Queue.element.

Doc from java.util.Queue.element.

Retrieves, but does not remove, the head of this queue. This method differs from peek only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

getback to summary
public E get(int index)

Implements abstract java.util.AbstractList.get.

Implements java.util.List.get.

Doc from java.util.AbstractList.get.

Returns the element at the specified position in this list.

Parameters
index:int

Doc from java.util.List.get.

index of the element to return

Returns:E

Doc from java.util.List.get.

the element at the specified position in this list

getCapacityback to summary
public int getCapacity()
getUnsafeback to summary
public E getUnsafe(int index)

Get without synchronization or bounds checking.

See Also
get(int)
growback to summary
protected void grow()
isEmptyback to summary
public boolean isEmpty()

Overrides java.util.AbstractCollection.isEmpty.

Implements java.util.Collection.isEmpty, java.util.List.isEmpty.

Doc from java.util.Collection.isEmpty.

Returns true if this collection contains no elements.

Returns:boolean

true if this collection contains no elements

offerback to summary
public boolean offer(E e)

Implements java.util.Queue.offer.

Doc from java.util.Queue.offer.

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions. When using a capacity-restricted queue, this method is generally preferable to add, which can fail to insert an element only by throwing an exception.

Parameters
e:E

the element to add

Returns:boolean

true if the element was added to this queue, else false

peekback to summary
public E peek()

Implements java.util.Queue.peek.

Doc from java.util.Queue.peek.

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

pollback to summary
public E poll()

Implements java.util.Queue.poll.

Doc from java.util.Queue.poll.

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Returns:E

the head of this queue, or null if this queue is empty

removeback to summary
public E remove()

Implements java.util.Queue.remove.

Doc from java.util.Queue.remove.

Retrieves and removes the head of this queue. This method differs from poll() only in that it throws an exception if this queue is empty.

Returns:E

the head of this queue

removeback to summary
public E remove(int index)

Overrides java.util.AbstractList.remove.

Implements java.util.List.remove.

Doc from java.util.AbstractList.remove.

Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters
index:int

Doc from java.util.List.remove.

the index of the element to be removed

Returns:E

Doc from java.util.List.remove.

the element previously at the specified position

setback to summary
public E set(int index, E element)

Overrides java.util.AbstractList.set.

Implements java.util.List.set.

Doc from java.util.AbstractList.set.

Replaces the element at the specified position in this list with the specified element (optional operation).

Parameters
index:int

Doc from java.util.List.set.

index of the element to replace

element:E

Doc from java.util.List.set.

element to be stored at the specified position

Returns:E

Doc from java.util.List.set.

the element previously at the specified position

sizeback to summary
public int size()

Implements abstract java.util.AbstractCollection.size.

Implements java.util.Collection.size, java.util.List.size.

Doc from java.util.Collection.size.

Returns the number of elements in this collection. If this collection contains more than Integer.MAX_VALUE elements, returns Integer.MAX_VALUE.

Returns:int

the number of elements in this collection