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

dk.rode.thesis.decorator
Class AppenderDecorator

java.lang.Object
  extended by dk.rode.thesis.decorator.SequenceDecorator<String>
      extended by dk.rode.thesis.decorator.AppenderDecorator
All Implemented Interfaces:
Sequence<String>, Copyable<Sequence<String>>, StrictCopyable<Sequence<String>>, Stringable<Sequence<String>>

@Participant(value="ConcreteDecorator")
public class AppenderDecorator
extends SequenceDecorator<String>
implements Sequence<String>

An appender decorator returns the String value from a decorated sequence prefixed and/or postfixed with values supplied at construction time, respectively. Given the prefix and postfix values xx and zz, the value returned will thus be xxYYzz, where YY is the value returned by the decorated sequence.

Only sequences returning strings can be decorated.

The default stringable policy used is DecoratedPolicy.HIDDEN.

Author:
Gunni Rode / rode.dk

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
private  CharSequence postfix
          Postfix to any value returned by the decorated sequence.
private  CharSequence prefix
          Prefix to any value returned by the decorated sequence.
 
Fields inherited from class dk.rode.thesis.decorator.SequenceDecorator
sequence
 
Constructor Summary
AppenderDecorator(Sequence<String> sequence, CharSequence prefix, CharSequence postfix)
          Constructor.
 
Method Summary
 AppenderDecorator copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
 String current()
          Returns the current element from this sequence.
private static String enclose(CharSequence prefix, CharSequence value, CharSequence postfix)
          Returns a string having one of the following formats depending on whether prefix and postfix are null, respectively: value: prefix and postfix are null.
 String next()
          Returns the next element from this sequence.
 
Methods inherited from class dk.rode.thesis.decorator.SequenceDecorator
bounded, consistent, equals, getSequence, getStringablePolicy, hashCode, reset, state, toString, toString, unique
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, 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
 

Field Detail

postfix

private final CharSequence postfix
Postfix to any value returned by the decorated sequence.

Can be null, i.e. not used.


prefix

private final CharSequence prefix
Prefix to any value returned by the decorated sequence.

Can be null, i.e. not used.

Constructor Detail

AppenderDecorator

public AppenderDecorator(@Participant(value="ConcreteComponent")
                         Sequence<String> sequence,
                         CharSequence prefix,
                         CharSequence postfix)
Constructor.

Parameters:
sequence - The sequence to decorate; cannot be null.
prefix - The prefix to use; null means none.
postfix - The postfix to use; null means none.
Throws:
NullPointerException - If sequence is null.
Method Detail

copy

public AppenderDecorator 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<String>
Specified by:
copy in interface Copyable<Sequence<String>>
Returns:
A copy of this sequence; never null.

current

public String 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<String>
Overrides:
current in class SequenceDecorator<String>
Returns:
The current element; never null.

enclose

private static final String enclose(CharSequence prefix,
                                    CharSequence value,
                                    CharSequence postfix)
Returns a string having one of the following formats depending on whether prefix and postfix are null, respectively:

Parameters:
prefix - The prefix, if any; can be null.
value - The value; cannot be null.
postfix - The postfix, if any; can be null.
Returns:
The concatenated string; never null.

next

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

Specified by:
next in interface Sequence<String>
Overrides:
next in class SequenceDecorator<String>
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.