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

dk.rode.thesis.decorator
Class UppercaseDecorator

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

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

An upper-case sequence decorator returns the string value returned by the decorated sequence in upper-case, for example a -> A.

A flag can be supplied at construction time which specifies if only the first character from the string value should be upper-cased, i.e. aaa -> Aaa as opposed to aaa -> AAA (default).

Only sequences returning strings can be decorated.

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  boolean firstOnly
          True if only the first character in the sequence value should be upper-cased, false if the entire value should be upper-cased.
 
Fields inherited from class dk.rode.thesis.decorator.SequenceDecorator
sequence
 
Constructor Summary
UppercaseDecorator(Sequence<String> sequence)
          Constructor.
UppercaseDecorator(Sequence<String> sequence, boolean firstOnly)
          Constructor.
 
Method Summary
 UppercaseDecorator 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.
 String next()
          Returns the next element from this sequence.
private static String toUpperCase(String value, boolean firstOnly)
          Returns an upper-cased string based on value.
 
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

firstOnly

private final boolean firstOnly
True if only the first character in the sequence value should be upper-cased, false if the entire value should be upper-cased.

Constructor Detail

UppercaseDecorator

public UppercaseDecorator(@Participant(value="ConcreteComponent")
                          Sequence<String> sequence)
Constructor.

The entire sequence value (String) will be upper-cased.

Parameters:
sequence - The sequence to decorate; cannot be null.
Throws:
NullPointerException - If sequence is null.

UppercaseDecorator

public UppercaseDecorator(@Participant(value="ConcreteComponent")
                          Sequence<String> sequence,
                          boolean firstOnly)
Constructor.

If firstOnly is true, only the first character in the values delivered by sequence will be upper-cased.

Parameters:
sequence - The sequence to decorate; cannot be null.
firstOnly - True if only the first character should be upper-cased, false for the entire value.
Throws:
NullPointerException - If sequence is null.
Method Detail

copy

public UppercaseDecorator 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.

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()

toUpperCase

private static final String toUpperCase(String value,
                                        boolean firstOnly)
Returns an upper-cased string based on value.

Parameters:
value - The value to upper-case (first); never null.
firstOnly - True if only the first character in value should be upper-cased.
Returns:
The upper-cased (first) string; 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.