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

dk.rode.thesis.singleton
Class SmileySequence

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.SmileySequence
All Implemented Interfaces:
Sequence<String>, Copyable<Sequence<String>>, StrictCopyable<Sequence<String>>, Stringable<Sequence<String>>

@Participant(value="Singleton")
@Singleton(value="getSequence")
public final class SmileySequence
extends ArraySequence<String>

A smiley sequence is a sequence delivering different smileys, e.g. :), *<;), :(, etc.

A smiley sequence is bounded, consistent, and unique with respect to its lifetime; the sequence of the generated smileys is determined randomly at construction time.

Implementation notes:
The SmileySequence uses double-checked locking to perform lazy initialisation of the singleton instance when first requested.

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

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.meta.model.Sequence
Sequence.State
 
Field Summary
private static SmileySequence instance
          Single instance of the sequence, lazily initialised using double-checked locking when first requested.
static int SIZE
          The number of different smileys returned by the sequence.
private static String[] smileys
          All generated smileys.
 
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 SmileySequence()
          Private off-limit constructor.
 
Method Summary
 SmileySequence copy()
          Returns this instance.
static SmileySequence getSequence()
          Returns the SmileySequence singleton instance to use.
private static String[] shuffleSmileys()
          Generates a random sequence of smileys to return by the smiley sequence.
 
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

instance

private static volatile SmileySequence instance
Single instance of the sequence, lazily initialised using double-checked locking when first requested.

Will be null until initialised.


SIZE

public static final int SIZE
The number of different smileys returned by the sequence.

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

See Also:
DanishAlphabetSequence.SIZE, NorwegianAlphabetSequence.SIZE, SimpsonsFamilySequence.SIZE, SimpsonsAndBouvierFamilySequence.SIZE

smileys

private static final String[] smileys
All generated smileys.

Constructor Detail

SmileySequence

private SmileySequence()
Private off-limit constructor.

Method Detail

copy

public SmileySequence copy()
Returns this instance.

Returns:
This instance; never null.

getSequence

public static final SmileySequence getSequence()
Returns the SmileySequence singleton instance to use.

If this is the first time the sequence is requested, it will be lazily initialised.

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

shuffleSmileys

private static final String[] shuffleSmileys()
Generates a random sequence of smileys to return by the smiley sequence.

Returns:
A sequence of smileys in form of a string array; 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.