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

dk.rode.thesis.visitor
Class CountingVisitor

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

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

A counting visitor counts the different types of value visitable sequences encountered during traversal, and is thus independent of any given scanner implementation.

A counting visitor does accumulate information about the visited sequences, but does not require any arguments at execution time. The result of the visitation can be fetched using the appropriate getter methods, for example getIntegerValued() for the number of sequences visited that delivered Integer values. Each time a given sequence instance is visited, the count will be increased, even if the sequence has already been visited. Before reuse, a counting visitor must be reset for the count to be accurate.

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

Field Summary
private  int composites
          Number of visitable sequences that were composite sequences with a specific value type.
private  int dateValued
          Number of visitable sequences that delivered Date values.
private  int integerValued
          Number of visitable sequences that delivered Integer values.
private  int longValued
          Number of visitable sequences that delivered Long values.
private  int stringValued
          Number of visitable sequences that delivered any type of CharSequence values.
private  int unknowns
          Number of visitable sequences that delivered unknown values (excluding composites).
 
Constructor Summary
CountingVisitor()
          No-arg constructor.
 
Method Summary
 int getComposites()
          Returns the number of value visitable sequences that were composites and where the type of value was unknown.
 int getDateValued()
          Returns the number of value visitable sequences that delivered Date values.
 int getIntegerValued()
          Returns the number of value visitable sequences that delivered Integer values.
 int getLongValued()
          Returns the number of value visitable sequences that delivered Long values.
 int getStringValued()
          Returns the number of value visitable sequences that delivered any type of CharSequence values.
 int getTotal()
          Returns the total number of value visitable sequences that were visited.
 int getUnknowns()
          Returns the number of value visitable sequences where the type of value was unknown, excluding composites.
 void reset()
          Resets this visitor before re-scanning.
 String toString()
          Returns the string representation of this visitor.
 void visitDateValued(Sequence<Date> sequence, Void unused)
          Visits a sequence that delivers Date sequence values.
 void visitIntegerValued(Sequence<Integer> sequence, Void unused)
          Visits a sequence that delivers Integer sequence values.
 void visitLongValued(Sequence<Long> sequence, Void unused)
          Visits a sequence that delivers Long sequence values.
 void visitStringValued(Sequence<? extends CharSequence> sequence, Void unused)
          Visits a sequence that delivers any type of value that implements the CharSequence interface, including CharSequence it self.
 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

composites

private int composites
Number of visitable sequences that were composite sequences with a specific value type.


dateValued

private int dateValued
Number of visitable sequences that delivered Date values.


integerValued

private int integerValued
Number of visitable sequences that delivered Integer values.


longValued

private int longValued
Number of visitable sequences that delivered Long values.


stringValued

private int stringValued
Number of visitable sequences that delivered any type of CharSequence values.


unknowns

private int unknowns
Number of visitable sequences that delivered unknown values (excluding composites).

Constructor Detail

CountingVisitor

public CountingVisitor()
No-arg constructor.

Method Detail

getComposites

public int getComposites()
Returns the number of value visitable sequences that were composites and where the type of value was unknown.

Returns:
The number of sequences.

getDateValued

public int getDateValued()
Returns the number of value visitable sequences that delivered Date values.

Returns:
The number of sequences.

getIntegerValued

public int getIntegerValued()
Returns the number of value visitable sequences that delivered Integer values.

Returns:
The number of sequences.

getLongValued

public int getLongValued()
Returns the number of value visitable sequences that delivered Long values.

Returns:
The number of sequences.

getStringValued

public int getStringValued()
Returns the number of value visitable sequences that delivered any type of CharSequence values.

Returns:
The number of sequences.

getTotal

public int getTotal()
Returns the total number of value visitable sequences that were visited.

Returns:
The number of sequences.

getUnknowns

public int getUnknowns()
Returns the number of value visitable sequences where the type of value was unknown, excluding composites.

Returns:
The number of sequences.

reset

public void reset()
Resets this visitor before re-scanning.


toString

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

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

visitDateValued

public void visitDateValued(Sequence<Date> sequence,
                            Void unused)
Description copied from interface: SequenceValueVisitor
Visits a sequence that delivers Date sequence values.

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

visitIntegerValued

public void visitIntegerValued(Sequence<Integer> sequence,
                               Void unused)
Description copied from interface: SequenceValueVisitor
Visits a sequence that delivers Integer sequence values.

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

visitLongValued

public void visitLongValued(Sequence<Long> sequence,
                            Void unused)
Description copied from interface: SequenceValueVisitor
Visits a sequence that delivers Long sequence values.

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

visitStringValued

public void visitStringValued(Sequence<? extends CharSequence> sequence,
                              Void unused)
Description copied from interface: SequenceValueVisitor
Visits a sequence that delivers any type of value that implements the CharSequence interface, including CharSequence it self.

Specified by:
visitStringValued in interface SequenceValueVisitor<Void>
Parameters:
sequence - The 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.