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

Class NorwegianAlphabetSequence

  extended by dk.rode.thesis.meta.model.AbstractSequence<E>
      extended by dk.rode.thesis.meta.model.ArraySequence<String>
          extended by dk.rode.thesis.singleton.NorwegianAlphabetSequence
All Implemented Interfaces:
Sequence<String>, Copyable<Sequence<String>>, StrictCopyable<Sequence<String>>, Stringable<Sequence<String>>

public final class NorwegianAlphabetSequence
extends ArraySequence<String>

A singleton alphabet sequence for letters in the Norwegian alphabet: a though z as well as , , and , all lower-cased.

Only a single instance of this class is created, and is available via the getInstance() method.

This class cannot be sub-classed.

Implementation notes:
A single instance of NorwegianAlphabetSequence is always created at class loading time in a thread-safe manner by using standard static initialisation. For example, accessing the static field SIZE will cause the singleton instance to be created. Hence, each call to getInstance() does not have to be synchronised or check to see if the single instance has been created.

A CallerClass is used to ensure that only this class itself can create the singleton instance.

Any singleton instance in Java is only a singleton per class loader if created based on and utilising intrinsic class features.

Note that the standard ArraySequence hashCode and equals(Object) still works for singleton sub-classes of it.

Gunni Rode / rode.dk
See Also:
DanishAlphabetSequence, SimpsonsFamilySequence, SimpsonsAndBouvierFamilySequence, SmileySequence

Nested Class Summary
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Field Summary
private static String[] alphabet
          The letters in the Norwegian alphabet.
private static NorwegianAlphabetSequence instance
          Single instance of the sequence, initialised thread-safe at class loading time.
static int SIZE
          The size of the Norwegian alphabet.
Fields inherited from class dk.rode.thesis.meta.model.ArraySequence
elements, index
Fields inherited from class dk.rode.thesis.meta.model.AbstractSequence
Constructor Summary
private NorwegianAlphabetSequence()
          Private no-arg constructor.
Method Summary
 NorwegianAlphabetSequence copy()
          Returns this instance.
static NorwegianAlphabetSequence getInstance()
          Returns the NorwegianAlphabetSequence singleton instance to use.
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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dk.rode.thesis.meta.model.Sequence
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString

Field Detail


private static final String[] alphabet
The letters in the Norwegian alphabet.


private static final NorwegianAlphabetSequence instance
Single instance of the sequence, initialised thread-safe at class loading time.

Never null.


public static final int SIZE
The size of the Norwegian alphabet.

Implementation notes:
Accessing this static field before getInstance() will cause the singleton instance to be created!

See Also:
DanishAlphabetSequence.SIZE, SimpsonsFamilySequence.SIZE, SimpsonsAndBouvierFamilySequence.SIZE, SmileySequence.SIZE
Constructor Detail


private NorwegianAlphabetSequence()
Private no-arg constructor.

SingletonError - If another class tries to invoke this constructor (via reflection).
Method Detail


public final NorwegianAlphabetSequence copy()
Returns this instance.

This instance; never null.


public static final NorwegianAlphabetSequence getInstance()
Returns the NorwegianAlphabetSequence singleton instance to use.

The sequence; never null.
See Also:

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.