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

dk.rode.thesis.visitor
Class VisitableCompositeSequence

java.lang.Object
  extended by dk.rode.thesis.meta.model.AbstractSequence<E>
      extended by dk.rode.thesis.composite.AbstractCompositeSequence<Object>
          extended by dk.rode.thesis.visitor.VisitableCompositeSequence
All Implemented Interfaces:
CompositeSequence<Object>, Sequence<Object>, Copyable<Sequence<Object>>, StrictCopyable<Sequence<Object>>, Stringable<Sequence<Object>>, TypeVisitableSequence<Object>, ValueVisitableSequence<Object>, Iterable<Sequence<? extends Object>>

@Participant(value="ConcreteElement")
public class VisitableCompositeSequence
extends AbstractCompositeSequence<Object>
implements ValueVisitableSequence<Object>, TypeVisitableSequence<Object>

An visitable composite sequence is value and type visitable, storing sequences regardless of the type of value they deliver.

The children of a composite sequence are NOT visited explicitly during visits to it! Their visitation must be handled by value and type scanners!

The value returned by the current() and next() methods is the value of the first contained sequence. In case a visitable composite sequence has no children, NULL is returned.

This implementation is not thread-safe.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
 
Fields inherited from class dk.rode.thesis.composite.AbstractCompositeSequence
sequences
 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
state
 
Constructor Summary
VisitableCompositeSequence()
          No-arg constructor.
VisitableCompositeSequence(CompositeStrategy strategy)
          Constructor.
VisitableCompositeSequence(VisitableCompositeSequence sequence)
          Copy constructor, which also copies associated sequences.
 
Method Summary
<P> void
accept(SequenceTypeVisitor<P> visitor, P argument)
          Visits this visitable sequence using the type visitor supplied as visitor.
<P> void
accept(SequenceValueVisitor<P> visitor, P argument)
          Visits this visitable sequence using the value visitor supplied as visitor.
 VisitableCompositeSequence copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 Object current()
          Returns the current element from this sequence.
 Object next()
          Returns the next element from this sequence.
 
Methods inherited from class dk.rode.thesis.composite.AbstractCompositeSequence
addSequence, bounded, calculateNextState, consistent, getCompositeStrategy, getSequences, getSequences, getSequences, getSequences, iterator, removeSequence, reset, setCompositeStrategy, size, unique
 
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence
getStringablePolicy, state, toString, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.meta.model.Sequence
bounded, consistent, reset, state, unique
 
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString
 

Constructor Detail

VisitableCompositeSequence

public VisitableCompositeSequence()
No-arg constructor.

The CompositeStrategy.DEFAULT strategy is used for traversal.


VisitableCompositeSequence

public VisitableCompositeSequence(CompositeStrategy strategy)
Constructor.

Parameters:
strategy - The traversal strategy; can be null, in which case CompositeStrategy.DEFAULT is used.

VisitableCompositeSequence

public VisitableCompositeSequence(VisitableCompositeSequence sequence)
Copy constructor, which also copies associated sequences.

Parameters:
sequence - The composite sequence to copy; cannot be null.
Throws:
NullPointerException - If sequence is null.
Method Detail

accept

public <P> void accept(SequenceTypeVisitor<P> visitor,
                       P argument)
Description copied from interface: TypeVisitableSequence
Visits this visitable sequence using the type visitor supplied as visitor.

Specified by:
accept in interface TypeVisitableSequence<Object>
Type Parameters:
P - The type of visitor-supplied argument. Use Void for visitors that do not need an additional argument.
Parameters:
visitor - The visitor; never null.
argument - A context supplied argument, if any.
See Also:
SequenceTypeVisitor.visitComposite(CompositeSequence, Object)

accept

public <P> void accept(SequenceValueVisitor<P> visitor,
                       P argument)
Description copied from interface: ValueVisitableSequence
Visits this visitable sequence using the value visitor supplied as visitor.

Specified by:
accept in interface ValueVisitableSequence<Object>
Type Parameters:
P - The type of visitor-supplied argument. Use Void for visitors that do not need an additional argument.
Parameters:
visitor - The visitor; never null.
argument - A context supplied argument, if any.
See Also:
SequenceVisitor.visitUnknown(Sequence, Object)

copy

public VisitableCompositeSequence copy()
Description copied from interface: Sequence
Returns a copy of this sequence that will start at the same sequence index as this sequence.

Specified by:
copy in interface Sequence<Object>
Specified by:
copy in interface Copyable<Sequence<Object>>
Returns:
A copy of this sequence; never null.

current

public Object current()
Description copied from interface: Sequence
Returns the current element from this sequence.

This method can be invoked even if Sequence.next() has not been invoked yet, thus delivering the initial value of this sequence.

Specified by:
current in interface Sequence<Object>
Returns:
The current element; never null.

next

public Object next()
Description copied from interface: Sequence
Returns the next element from this sequence.

Specified by:
next in interface Sequence<Object>
Returns:
The next element; never null.
See Also:
Sequence.current(), Sequence.state()

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.