org.perfectjpattern.core.structural.adapter
Class List2QueueAdapter<E>
java.lang.Object
org.perfectjpattern.core.structural.AbstractSurrogate<T,A>
org.perfectjpattern.core.structural.adapter.Adapter<Queue<E>,List<E>>
org.perfectjpattern.core.structural.adapter.List2QueueAdapter<E>
- Type Parameters:
E
- Type of the Queue
elements
- All Implemented Interfaces:
- InvocationHandler, IAdapter<Queue<E>,List<E>>, ISurrogate<Queue<E>>
public class List2QueueAdapter<E>
- extends Adapter<Queue<E>,List<E>>
Adapter that provides a Queue
based on a List
implementation.
That is, it adapts the List
to behave and look like a Queue
.
Please note that this is not an exhaustive implementation of Queue
nor it replaces the proper JDK Queue
implementations. The purpose
of this Adapter is only to demonstrate:
- How to use PerfectJPattern's
Adapter
implementation to adapt an
implementation to a given target interface
- How the componentized Adapter facilitates adapting types by means of:
Noteworthy is how this implementation did NOT have to provide a full blown
implementation of all of the Target Queue
interface methods e.g.
Collection.addAll(Collection)
or Collection.toArray()
as
the call forwarding is automatically handled by PerfectJPattern's
Adapter
- Version:
- $Revision: 1.0 $Date: Feb 5, 2009 8:55:42 PM $
- Author:
- Giovanni Azua
-
-
Method Summary |
E |
element()
Retrieves, but does not remove, the head of this queue. |
E |
peek()
Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty. |
E |
poll()
Retrieves and removes the head of this queue,
or returns null if this queue is empty. |
E |
remove()
Retrieves and removes the head of this queue. |
List2QueueAdapter
public List2QueueAdapter(List<E> anAdaptee)
throws IllegalArgumentException
- Constructs a
List2QueueAdapter
from the underlying Adaptee
List
implementation.
- Parameters:
anAdaptee
- The Adaptee List
implementation to adapt
- Throws:
IllegalArgumentException
- 'anAdaptee' must not be null
remove
public E remove()
throws NoSuchElementException
- 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:
- the head of this queue
- Throws:
NoSuchElementException
- if this queue is empty
poll
public E poll()
- Retrieves and removes the head of this queue,
or returns null if this queue is empty.
- Returns:
- the head of this queue, or null if this queue is empty
element
public E 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:
- the head of this queue
- Throws:
NoSuchElementException
- if this queue is empty
peek
public E peek()
- Retrieves, but does not remove, the head of this queue,
or returns null if this queue is empty.
- Returns:
- the head of this queue, or null if this queue is empty
Copyright © 2007-2009. All Rights Reserved.