Evaluating Software Design Patterns
— the "Gang of Four" patterns implemented in Java 6

dk.rode.thesis.adapter
Class AdapterStrategy

java.lang.Object
  extended by dk.rode.thesis.adapter.AdapterStrategy

public class AdapterStrategy
extends Object

Simple adapter strategies used in conjunction with SequenceAdapter instances.

Each strategy is stateless, and thus thread-safe.

Implementation notes:
Adapter composition is implemented according to the Strategy pattern. As the explicit type parameters are important and differs between each concrete strategy, theses strategies cannot be declared as values in an enumeration. A benefit of this is that the class is open for sub-classing.

Each strategy is implemented as an anonymous class implementing the AdapterDelegate interface, which is by it self a representation of adaptation. It is common practice in Java to utilise anonymous inner class to implement adapters.

All strategies for adaptation defined here are state preserving and imply a simple representation shift except for the LONG_TO_INTEGER and BIGINTEGER_TO_LONG strategies, which may truncate values.

Author:
Gunni Rode / rode.dk

Field Summary
static AdapterDelegate<Object,Object> ANY_TO_OBJECT
          A strategy to shift from an any type into Object.
static AdapterDelegate<Object,String> ANY_TO_STRING
          A strategy to shift from an Object or wild-card representation to a String representation by invoking toString() on the object.
static AdapterDelegate<BigInteger,Long> BIGINTEGER_TO_LONG
          A strategy to shift from a BigInteger representation to a Long representation.
static AdapterDelegate<CharSequence,Long> CHAR_TO_LONG
          A strategy to shift from a CharSequence representation to a Long representation.
static AdapterDelegate<CharSequence,String> CHAR_TO_STRING
          A strategy to shift from a CharSequence representation to a String representation.
static AdapterDelegate<Long,Integer> LONG_TO_INTEGER
          A strategy to shift from a Long representation to an Integer representation.
static AdapterDelegate<Long,String> LONG_TO_STRING
          A strategy to shift from a Long representation to a String representation.
static AdapterDelegate<Number,String> NUMBER_TO_STRING
          A strategy to shift from a Number representation to a String representation.
static AdapterDelegate<String,CharSequence> STRING_TO_CHAR
          A strategy to shift from a String representation to a CharSequence representation via a simple implicit cast.
 
Constructor Summary
protected AdapterStrategy()
          No-arg sub-class constructor.
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ANY_TO_OBJECT

public static final AdapterDelegate<Object,Object> ANY_TO_OBJECT
A strategy to shift from an any type into Object.

This is useful if wild-cards is to be used.


ANY_TO_STRING

public static final AdapterDelegate<Object,String> ANY_TO_STRING
A strategy to shift from an Object or wild-card representation to a String representation by invoking toString() on the object.


BIGINTEGER_TO_LONG

public static final AdapterDelegate<BigInteger,Long> BIGINTEGER_TO_LONG
A strategy to shift from a BigInteger representation to a Long representation.

The long representation is simply truncated. Hence, this strategy cannot be guaranteed to preserve the entire state.


CHAR_TO_LONG

public static final AdapterDelegate<CharSequence,Long> CHAR_TO_LONG
A strategy to shift from a CharSequence representation to a Long representation.


CHAR_TO_STRING

public static final AdapterDelegate<CharSequence,String> CHAR_TO_STRING
A strategy to shift from a CharSequence representation to a String representation.


LONG_TO_INTEGER

public static final AdapterDelegate<Long,Integer> LONG_TO_INTEGER
A strategy to shift from a Long representation to an Integer representation.

The integer representation is simply truncated. Hence, this strategy cannot be guaranteed to preserve the entire state, e.g. from 64 to 32 bit values.


LONG_TO_STRING

public static final AdapterDelegate<Long,String> LONG_TO_STRING
A strategy to shift from a Long representation to a String representation.


NUMBER_TO_STRING

public static final AdapterDelegate<Number,String> NUMBER_TO_STRING
A strategy to shift from a Number representation to a String representation.


STRING_TO_CHAR

public static final AdapterDelegate<String,CharSequence> STRING_TO_CHAR
A strategy to shift from a String representation to a CharSequence representation via a simple implicit cast.

Constructor Detail

AdapterStrategy

protected AdapterStrategy()
No-arg sub-class constructor.


Gunni Rode / rode.dk

Feel free to use and/or modify the Java 6 source code developed for this thesis AT YOUR OWN RISK, but note that the source code comes WITHOUT ANY — and I do mean WITHOUT ANY — form of warranty WHAT SO EVER!

The original thesis and source code are available at rode.dk/thesis.