Top Description Fields Constructors Methods
org.apache.commons.collections4.queue

public Class SynchronizedQueue<E>

extends SynchronizedCollection<E>
implements Queue<E>
Class Inheritance
All Implemented Interfaces
java.util.Queue, java.util.Collection, java.lang.Iterable
Type Parameters
<E>
the type of the elements in the collection
Imports
java.util.Queue, org.apache.commons.collections4.collection.SynchronizedCollection

Decorates another Queue to synchronize its behaviour for a multi-threaded environment.

Methods are synchronized, then forwarded to the decorated queue. Iterators must be separately synchronized around the loop.

Since
4.2

Field Summary

Modifier and TypeField and Description
private static final long
Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
lock

Constructor Summary

AccessConstructor and Description
protected
SynchronizedQueue(final Queue<E>
the queue to decorate, must not be null
queue
)

Constructor that wraps (not copies).

protected
SynchronizedQueue(final Queue<E>
the queue to decorate, must not be null
queue
,
final Object
the lock to use, must not be null
lock
)

Constructor that wraps (not copies).

Method Summary

Modifier and TypeMethod and Description
protected Queue<E>

Returns:

the decorated queue
decorated
()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.decorated.

Gets the queue being decorated.
public E
element()

Implements java.util.Queue.element.

Retrieves, but does not remove, the head of this queue.
public boolean
equals(final Object
object to be compared for equality with this collection
object
)

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.equals.

Implements java.util.Collection.equals.

Compares the specified object with this collection for equality.
public int
hashCode()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.hashCode.

Implements java.util.Collection.hashCode.

Returns the hash code value for this collection.
public boolean
offer(final 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 static <
the type of the elements in the queue
E
>
SynchronizedQueue<E>

Returns:

a new synchronized Queue
synchronizedQueue
(final Queue<E>
the queue to decorate, must not be null
queue
)

Factory method to create a synchronized queue.

Inherited from org.apache.commons.collections4.collection.SynchronizedCollection:
addaddAllclearcontainscontainsAllisEmptyiteratorremoveremoveAllremoveIfretainAllsizesynchronizedCollectiontoArraytoArraytoString

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides org.apache.commons.collections4.collection.SynchronizedCollection.serialVersionUID.

Serialization version

Constructor Detail

SynchronizedQueueback to summary
protected SynchronizedQueue(final Queue<E> queue)

Constructor that wraps (not copies).

Parameters
queue:Queue<E>

the queue to decorate, must not be null

Exceptions
NullPointerException:
if queue is null
SynchronizedQueueback to summary
protected SynchronizedQueue(final Queue<E> queue, final Object lock)

Constructor that wraps (not copies).

Parameters
queue:Queue<E>

the queue to decorate, must not be null

lock:Object

the lock to use, must not be null

Exceptions
NullPointerException:
if queue or lock is null

Method Detail

decoratedback to summary
protected Queue<E> decorated()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.decorated.

Gets the queue being decorated.

Returns:Queue<E>

the decorated queue

Annotations
@Override
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

Annotations
@Override
equalsback to summary
public boolean equals(final Object object)

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.equals.

Implements java.util.Collection.equals.

Doc from java.util.Collection.equals.

Compares the specified object with this collection for equality.

While the Collection interface adds no stipulations to the general contract for the Object.equals, programmers who implement the Collection interface "directly" (in other words, create a class that is a Collection but is not a Set or a List) must exercise care if they choose to override the Object.equals. It is not necessary to do so, and the simplest course of action is to rely on Object's implementation, but the implementor may wish to implement a "value comparison" in place of the default "reference comparison." (The List and Set interfaces mandate such value comparisons.)

The general contract for the Object.equals method states that equals must be symmetric (in other words, a.equals(b) if and only if b.equals(a)). The contracts for List.equals and Set.equals state that lists are only equal to other lists, and sets to other sets. Thus, a custom equals method for a collection class that implements neither the List nor Set interface must return false when this collection is compared to any list or set. (By the same logic, it is not possible to write a class that correctly implements both the Set and List interfaces.)

Parameters
object:Object

object to be compared for equality with this collection

Returns:boolean

true if the specified object is equal to this collection

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides org.apache.commons.collections4.collection.SynchronizedCollection.hashCode.

Implements java.util.Collection.hashCode.

Doc from java.util.Collection.hashCode.

Returns the hash code value for this collection. While the Collection interface adds no stipulations to the general contract for the Object.hashCode method, programmers should take note that any class that overrides the Object.equals method must also override the Object.hashCode method in order to satisfy the general contract for the Object.hashCode method. In particular, c1.equals(c2) implies that c1.hashCode()==c2.hashCode().

Returns:int

the hash code value for this collection

Annotations
@Override
offerback to summary
public boolean offer(final 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

Annotations
@Override
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

Annotations
@Override
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

Annotations
@Override
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

Annotations
@Override
synchronizedQueueback to summary
public static <E> SynchronizedQueue<E> synchronizedQueue(final Queue<E> queue)

Factory method to create a synchronized queue.

Parameters
<E>
the type of the elements in the queue
queue:Queue<E>

the queue to decorate, must not be null

Returns:SynchronizedQueue<E>

a new synchronized Queue

Exceptions
NullPointerException:
if queue is null