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

dk.rode.thesis.visitor
Class SimpleScanner

java.lang.Object
  extended by dk.rode.thesis.visitor.SimpleScanner
All Implemented Interfaces:
SequenceTypeScanner, SequenceValueScanner

@Participant(value="ObjectStructure")
public class SimpleScanner
extends Object
implements SequenceTypeScanner, SequenceValueScanner

A simple scanner can traverse both type and value visitable sequences based on a traversal strategy that can be supplied at construction time, or changed runtime using the setCompositeStrategy(CompositeStrategy) method.

Author:
Gunni Rode / rode.dk

Field Summary
private  CompositeStrategy strategy
          The composite traversal strategy to use.
 
Constructor Summary
SimpleScanner()
          No-arg constructor.
SimpleScanner(CompositeStrategy strategy)
          Constructor.
 
Method Summary
 CompositeStrategy getCompositeStrategy()
          Return the currently used strategy by this scanner to traverse sequence structures.
<P> void
scan(TypeVisitableSequence<?> sequence, SequenceTypeVisitor<P> visitor, P argument)
          Performs the traversal of the sequence structure starting with sequence using the type visitor supplied as visitor.
<P> void
scan(ValueVisitableSequence<?> sequence, SequenceValueVisitor<P> visitor, P argument)
          Performs the traversal of the sequence structure starting with sequence using the value visitor supplied as visitor.
 void setCompositeStrategy(CompositeStrategy strategy)
          Sets the strategy to use by this scanner to traverse sequence structures to strategy
 String toString()
          Returns the string representation of this simple scanner.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

strategy

private CompositeStrategy strategy
The composite traversal strategy to use.

Null means default strategy per composite.

Constructor Detail

SimpleScanner

public SimpleScanner()
No-arg constructor.

The default strategy is used per composite.


SimpleScanner

public SimpleScanner(CompositeStrategy strategy)
Constructor.

Parameters:
strategy - The composite strategy to use for the traversal; can be null, i.e. default.
Method Detail

getCompositeStrategy

public CompositeStrategy getCompositeStrategy()
Return the currently used strategy by this scanner to traverse sequence structures.

Returns:
The used strategy; null means default per composite.
See Also:
setCompositeStrategy(CompositeStrategy), CompositeSequence.getCompositeStrategy()

scan

public <P> void scan(TypeVisitableSequence<?> sequence,
                     SequenceTypeVisitor<P> visitor,
                     P argument)
Description copied from interface: SequenceTypeScanner
Performs the traversal of the sequence structure starting with sequence using the type visitor supplied as visitor. If sequence is non-composite, it will be the only sequence visited.

For each type visitable sequence found in the sequence structure, the TypeVisitableSequence.accept(SequenceTypeVisitor, Object) visitation method is invoked.

Specified by:
scan in interface SequenceTypeScanner
Type Parameters:
P - The type of the additional parameter to required by visitor. Use Void for visitors that do not need an additional parameter.
Parameters:
sequence - The starting sequence ("root"); cannot be null.
visitor - The type visitor to use; cannot be null.
argument - A visitor specified argument, if any; nullability determined by visitor.
Throws:
NullPointerException - If sequence or visitor are null.

scan

public <P> void scan(ValueVisitableSequence<?> sequence,
                     SequenceValueVisitor<P> visitor,
                     P argument)
Description copied from interface: SequenceValueScanner
Performs the traversal of the sequence structure starting with sequence using the value visitor supplied as visitor. If sequence is non-composite, it will be the only sequence visited.

For each value visitable sequence found in the sequence structure, the ValueVisitableSequence.accept(SequenceValueVisitor, Object) visitation method is invoked.

Specified by:
scan in interface SequenceValueScanner
Type Parameters:
P - The type of the additional parameter to required by visitor. Use Void for visitors that do not need an additional parameter.
Parameters:
sequence - The starting sequence ("root"); cannot be null.
visitor - The value visitor to use; cannot be null.
argument - A visitor specified argument, if any; nullability determined by visitor.
Throws:
NullPointerException - If sequence or visitor are null.

setCompositeStrategy

public void setCompositeStrategy(CompositeStrategy strategy)
Sets the strategy to use by this scanner to traverse sequence structures to strategy

Parameters:
strategy - The strategy to use; can be null, which means default strategy per composite.
See Also:
getCompositeStrategy(), CompositeSequence.getCompositeStrategy()

toString

public String toString()
Returns the string representation of this simple scanner.

Overrides:
toString in class Object
Returns:
The string representation; never null.

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.