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

dk.rode.thesis.composite
Enum CompositeStrategy

java.lang.Object
  extended by java.lang.Enum<CompositeStrategy>
      extended by dk.rode.thesis.composite.CompositeStrategy
All Implemented Interfaces:
Serializable, Comparable<CompositeStrategy>

public enum CompositeStrategy
extends Enum<CompositeStrategy>

Strategies for traversing composite sequence graphs.

Implementation notes:
Composite strategies are implemented according to the Strategy pattern.

Author:
Gunni Rode / rode.dk

Enum Constant Summary
BREATH_FIRST
          Performs a breath first traversal.
COMBINED
          When a CompositeSequence is reached, its default strategy is used to traverse onwards.
DEFAULT
          Performs a depth first traversal returning all reachable sequences.
DEPTH_FIRST
          Performs a depth first traversal.
 
Method Summary
<E> List<Sequence<? extends E>>
traverse(Sequence<? extends E> root, Boolean type)
          Returns an ordered list containing all sequences reachable from root, including root.
protected abstract
<E,C extends List<Sequence<? extends E>>>
C
traverse(Sequence<? extends E> sequence, Boolean type, C sequences, CompositeStrategy strategy)
          Adds all sequences reachable from sequence to sequences as dictated by this strategy, including sequence if not already added.
static CompositeStrategy valueOf(String name)
          Returns the enum constant of this type with the specified name.
static CompositeStrategy[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

BREATH_FIRST

public static final CompositeStrategy BREATH_FIRST
Performs a breath first traversal.


COMBINED

public static final CompositeStrategy COMBINED
When a CompositeSequence is reached, its default strategy is used to traverse onwards.


DEFAULT

public static final CompositeStrategy DEFAULT
Performs a depth first traversal returning all reachable sequences.

See Also:
DEPTH_FIRST

DEPTH_FIRST

public static final CompositeStrategy DEPTH_FIRST
Performs a depth first traversal.

Method Detail

traverse

public final <E> List<Sequence<? extends E>> traverse(Sequence<? extends E> root,
                                                      Boolean type)
Returns an ordered list containing all sequences reachable from root, including root.

type determines the types of sequences to include in the returned list:

Type Parameters:
E - The type of values delivered by sequence.
Parameters:
root - The composite sequence to start from; cannot be null.
type - The type of traversal; can be null, i.e. return all reachable sequences.
Returns:
An ordered list of reachable sequences; never null, but can be empty.
Throws:
NullPointerException - If root is null.

traverse

protected abstract <E,C extends List<Sequence<? extends E>>> C traverse(Sequence<? extends E> sequence,
                                                                        Boolean type,
                                                                        C sequences,
                                                                        CompositeStrategy strategy)
Adds all sequences reachable from sequence to sequences as dictated by this strategy, including sequence if not already added.

type determines the types of sequences to include in the returned list:

Type Parameters:
E - The type of sequence values.
C - The actual type of list to add the sequences to.
Parameters:
sequence - The current sequence; cannot be null.
type - The type of traversal; can be null, i.e. return all reachable sequences.
sequences - The list to add the reached sequences; never null.
strategy - The strategy to apply for all attached sequences, if any; never null.
Returns:
The sequences list; cannot be null.
Throws:
NullPointerException - If sequence is null.

valueOf

public static CompositeStrategy valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

values

public static CompositeStrategy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (CompositeStrategy c : CompositeStrategy.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

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.