datapacket
Class ADataPacketAlgoCmd<R,D,P>

java.lang.Object
  extended by datapacket.ADataPacketAlgoCmd<R,D,P>
Type Parameters:
R - The return type
D - The data type held by the host
P - The input parameter type
All Implemented Interfaces:
IExtVisitorCmd<R,java.lang.Class<?>,P,ADataPacket>, java.io.Serializable

public abstract class ADataPacketAlgoCmd<R,D,P>
extends java.lang.Object
implements IExtVisitorCmd<R,java.lang.Class<?>,P,ADataPacket>

A DataPacketAlgo command that is designed to work on a DataPacket host.
This convenience class both simplifies the command code but also increase type safety by restricting the host type.
Usage:

 myDataPacketAlgo.addCmd(MyData.class, new ADataPacketAlgoCmd<MyReturn, MyData, MyParam>(){
     private static final long serialVersionUID = aGeneratedUIDvalue;
     
     public MyReturn apply(DataPacket<MyData> host, MyParam... params){
         // your code here
     }
 }
 
Note: In Eclipse, the auto-generation of the implemented methods of this class does not work properly. The concrete apply method below is replicated by the automatic method generator because it doesn't recognize that the method already exists and is final. Luckily, a compiler error message gets generated in the attempt to override a final method. Simply delete the extraneous auto-generated method.

Author:
Stephen Wong (c) 2010
See Also:
Serialized Form

Field Summary
private static long serialVersionUID
           
 
Constructor Summary
ADataPacketAlgoCmd()
           
 
Method Summary
<T extends IExtVisitorHost<java.lang.Class<?>,? super ADataPacket>>
R
apply(java.lang.Class<?> index, T host, P... params)
          The actual method called by the host visitor when the associated case is invoked.
abstract  R apply(DataPacket<D> host, P... params)
          Abstract method that actually performs the processing of the case.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values
Constructor Detail

ADataPacketAlgoCmd

public ADataPacketAlgoCmd()
Method Detail

apply

public final <T extends IExtVisitorHost<java.lang.Class<?>,? super ADataPacket>> R apply(java.lang.Class<?> index,
                                                                                         T host,
                                                                                         P... params)
The actual method called by the host visitor when the associated case is invoked. This method simply forwards the call to the abstract apply method, performing an unchecked cast of the host to the required DataPacket type.

Specified by:
apply in interface IExtVisitorCmd<R,java.lang.Class<?>,P,ADataPacket>
Type Parameters:
T - The type of the host the is expected to call this method. T is restricted to be a subclass of IExtVisitorHost<I, ? super H>
Parameters:
index - The Class object used to identify the host
host - The host calling the visitor
params - Vararg input parameters to be used for processing the host
Returns:
The result of this case.

apply

public abstract R apply(DataPacket<D> host,
                        P... params)
Abstract method that actually performs the processing of the case. Here, the host is strongly typed to be the DataPacket type appropriate for the case (D).

Parameters:
host - The DataPacket host calling the visitor
params - Vararg input parameter to be used for processing the host
Returns:
The result of this case.