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

dk.rode.thesis.singleton
Class NorwegianAlphabetSequence

java.lang.Object
  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>>

@Participant(value="Singleton")
@Singleton
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.

Author:
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
Sequence.State
 
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
state
 
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
state
 
Methods inherited from interface dk.rode.thesis.strategy.Stringable
getStringablePolicy, toString
 

Field Detail

alphabet

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


instance

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

Never null.


SIZE

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

NorwegianAlphabetSequence

private NorwegianAlphabetSequence()
Private no-arg constructor.

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

copy

public final NorwegianAlphabetSequence copy()
Returns this instance.

Returns:
This instance; never null.

getInstance

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

Returns:
The sequence; never null.
See Also:
Singleton

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.