org.perfectjpattern.core.structural.adapter
Class List2QueueAdapter<E>

java.lang.Object
  extended by org.perfectjpattern.core.structural.AbstractSurrogate<T,A>
      extended by org.perfectjpattern.core.structural.adapter.Adapter<Queue<E>,List<E>>
          extended by 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:

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
 

Constructor Summary
List2QueueAdapter(List<E> anAdaptee)
          Constructs a List2QueueAdapter from the underlying Adaptee List implementation.
 
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.
 
Methods inherited from class org.perfectjpattern.core.structural.adapter.Adapter
getAdaptee, getTarget, invokeUnderlying, setAdaptingStrategy
 
Methods inherited from class org.perfectjpattern.core.structural.AbstractSurrogate
equals, getComponent, getComponentClass, getUnderlying, hashCode, invoke
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.perfectjpattern.core.api.structural.ISurrogate
getComponent
 
Methods inherited from interface java.lang.reflect.InvocationHandler
invoke
 

Constructor Detail

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
Method Detail

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.