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

dk.rode.thesis.visitor
Class TypeVisitor

java.lang.Object
  extended by dk.rode.thesis.visitor.TypeVisitor
All Implemented Interfaces:
SequenceTypeVisitor<Void>, SequenceVisitor<Void>

@Participant(value="ConcreteVisitor")
public class TypeVisitor
extends Object
implements SequenceTypeVisitor<Void>

A type visitor collects visited sequences based on acceptance of specific sequence types.

It handles only type visitable sequences.

The collected types correspond to the visitation methods overridden by sub-classes of this visitor. If this visitor is used as is, it will accept no sequence types: each visitation method does nothing per default. A sub-class must simply invoke approve(Sequence) to signal that a given visited sequence is approved.

The visitor accumulates the visited sequences in visitation order. They can be collected after visitation via the getApproved() method. A given sequence is only included once in the returned list, based on equals, not identity.

Author:
Gunni Rode / rode.dk
See Also:
LoggingVisitor, CountingVisitor, SimpleScanner

Field Summary
private  Set<Sequence<?>> approved
          The set containing the approved sequences, in order.
 
Constructor Summary
TypeVisitor()
          No-arg constructor.
 
Method Summary
protected  void approve(Sequence<?> sequence)
          Approves the visited sequence supplied as sequence.
 int approved()
          Returns the number of sequences approved by this visitor.
 void clear()
          Clears the accumulated approved sequences, so this visitor can be reused.
 List<Sequence<?>> getApproved()
          Returns a list containing the sequences approved by this type visitor, in visitation order.
 String toString()
          Returns the string representation of this visitor.
 void visitComposite(CompositeSequence<?> sequence, Void unused)
          Visits a composite sequence.
 void visitMemorizable(MemorizableSequence<?> sequence, Void unused)
          Visits a memorizable sequence.
 void visitObservable(ObservableSequence<?,?,?> sequence, Void unused)
          Visits an observable sequence.
 void visitReversible(ReversibleSequence<?> sequence, Void unused)
          Visits a reversible sequence.
 void visitStateable(StateableSequence<?> sequence, Void unused)
          Visits a stateable sequence.
 void visitUnknown(Sequence<?> sequence, Void unused)
          Visits a sequence that cannot be visited by any other visitation methods declared by this visitor.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

approved

private final Set<Sequence<?>> approved
The set containing the approved sequences, in order.

Never null, but may be empty.

Constructor Detail

TypeVisitor

public TypeVisitor()
No-arg constructor.

Method Detail

approve

protected void approve(Sequence<?> sequence)
Approves the visited sequence supplied as sequence.

Parameters:
sequence - The sequence to approve; cannot be null.
Throws:
NullPointerException - if sequence is null.

approved

public int approved()
Returns the number of sequences approved by this visitor.

Returns:
The number of sequences approved.
See Also:
getApproved()

clear

public void clear()
Clears the accumulated approved sequences, so this visitor can be reused.


getApproved

public List<Sequence<?>> getApproved()
Returns a list containing the sequences approved by this type visitor, in visitation order.

Modifying the returned list will not affect this visitor.

Returns:
The list of sequences approved; never null, but can be empty.

toString

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

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

visitComposite

public void visitComposite(CompositeSequence<?> sequence,
                           Void unused)
Description copied from interface: SequenceTypeVisitor
Visits a composite sequence.

Specified by:
visitComposite in interface SequenceTypeVisitor<Void>
Parameters:
sequence - The composite sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

visitMemorizable

public void visitMemorizable(MemorizableSequence<?> sequence,
                             Void unused)
Description copied from interface: SequenceTypeVisitor
Visits a memorizable sequence.

Specified by:
visitMemorizable in interface SequenceTypeVisitor<Void>
Parameters:
sequence - The memorizable sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

visitObservable

public void visitObservable(ObservableSequence<?,?,?> sequence,
                            Void unused)
Description copied from interface: SequenceTypeVisitor
Visits an observable sequence.

Specified by:
visitObservable in interface SequenceTypeVisitor<Void>
Parameters:
sequence - The observable sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

visitReversible

public void visitReversible(ReversibleSequence<?> sequence,
                            Void unused)
Description copied from interface: SequenceTypeVisitor
Visits a reversible sequence.

Specified by:
visitReversible in interface SequenceTypeVisitor<Void>
Parameters:
sequence - The reversible sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

visitStateable

public void visitStateable(StateableSequence<?> sequence,
                           Void unused)
Description copied from interface: SequenceTypeVisitor
Visits a stateable sequence.

Specified by:
visitStateable in interface SequenceTypeVisitor<Void>
Parameters:
sequence - The stateable sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

visitUnknown

public void visitUnknown(Sequence<?> sequence,
                         Void unused)
Description copied from interface: SequenceVisitor
Visits a sequence that cannot be visited by any other visitation methods declared by this visitor.

Specified by:
visitUnknown in interface SequenceVisitor<Void>
Parameters:
sequence - The sequence to visit; never null.
unused - A visitor-specified argument, if any; nullability determined by the visitor implementation.

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.