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

dk.rode.thesis.prototype
Class SymbolSequence

java.lang.Object
  extended by dk.rode.thesis.meta.model.AbstractSequence<E>
      extended by dk.rode.thesis.meta.model.ArraySequence<CharSequence>
          extended by dk.rode.thesis.prototype.SymbolSequence
All Implemented Interfaces:
Sequence<CharSequence>, Copyable<Sequence<CharSequence>>, StrictCopyable<Sequence<CharSequence>>, Stringable<Sequence<CharSequence>>

@Participant(value="ConcretePrototype")
public class SymbolSequence
extends ArraySequence<CharSequence>

A cloneable symbol sequence can be cloned by using the copy() method, or by using Java's built-in clone mechanism by calling clone().

The following symbols are allowed:

   ! " # ¤ % & / ( ) = ? < > @ £ $ € { [ ] } + | ~ : * 
 
A symbol sequence thus acts as a prototype for similar sequences containing the same symbols, in order.

A symbol sequence is bounded, consistent, and unique.

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 static CharSequence[] SYMBOLS
          The various symbols allowed in a symbol sequence.
 
Fields inherited from class dk.rode.thesis.meta.model.ArraySequence
elements, index
 
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
state
 
Constructor Summary
SymbolSequence()
          No-arg constructor.
SymbolSequence(char... symbols)
          Constructor.
SymbolSequence(SymbolSequence sequence)
          Copy constructor.
 
Method Summary
 SymbolSequence clone()
          Clones this symbol sequence and returns the clone (copy).
 SymbolSequence copy()
          Returns a copy of this sequence that will start at the same sequence index as this sequence.
static CharSequence[] getAllowedSymbols()
          Returns the various symbols allowed in any symbol sequence.
private static CharSequence[] validate(char[] symbols)
          Validates the symbols supplied in symbols.
 
Methods inherited from class dk.rode.thesis.meta.model.ArraySequence
bounded, consistent, current, equals, hashCode, next, reset, size, unique
 
Methods inherited from class dk.rode.thesis.meta.model.AbstractSequence
getStringablePolicy, state, toString, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface dk.rode.thesis.meta.model.Sequence
state
 
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString
 

Field Detail

SYMBOLS

private static final CharSequence[] SYMBOLS
The various symbols allowed in a symbol sequence.

The allowed symbols are:

   ! " # ¤ % & / ( ) = ? < > @ £ $ € { [ ] } + | ~ : * 
 
Trying to construct a symbol sequence with other symbols is an error.

Constructor Detail

SymbolSequence

public SymbolSequence()
No-arg constructor.

All allowed allowed symbols are used.


SymbolSequence

public SymbolSequence(char... symbols)
Constructor.

The symbols supplied as symbols are used in this symbol sequence.

Parameters:
symbols - The symbols from the allowed symbols to use in this sequence; cannot be null or be empty.
Throws:
NullPointerException - If symbols is null.
IllegalArgumentException - If symbols is empty, or if it contains symbols not found in the allowed symbols.

SymbolSequence

public SymbolSequence(SymbolSequence sequence)
Copy constructor.

This sequence starts at the current index of sequence.

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

clone

public SymbolSequence clone()
Clones this symbol sequence and returns the clone (copy).

Overrides:
clone in class Object
Returns:
A clone (copy) of this sequence; never null.

copy

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

Returns:
A copy of this sequence; never null.

getAllowedSymbols

public static final CharSequence[] getAllowedSymbols()
Returns the various symbols allowed in any symbol sequence.

The allowed symbols are:

   ! " # ¤ % & / ( ) = ? < > @ £ $ € { [ ] } + | ~ : * 
 
Trying to construct a symbol sequence with other symbols is an error.

Modifying the returned array will only have local effect.

Returns:
The allowed symbols; never null.

validate

private static final CharSequence[] validate(char[] symbols)
Validates the symbols supplied in symbols.

If each char in symbols is contained in SYMBOLS, this method returns silently with a CharSequence array corresponding to the symbols. Otherwise an exception is thrown.

Parameters:
symbols - The symbols to validate; cannot be null.
Returns:
A corresponding CharSequence array; never null.
Throws:
NullPointerException - If symbols is null.
IllegalArgumentException - If symbols contains an illegal symbol.

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.