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

dk.rode.thesis.strategy
Enum SequencePolicy

java.lang.Object
  extended by java.lang.Enum<SequencePolicy>
      extended by dk.rode.thesis.strategy.SequencePolicy
All Implemented Interfaces:
StringablePolicy<Sequence<?>>, Serializable, Comparable<SequencePolicy>

public enum SequencePolicy
extends Enum<SequencePolicy>
implements StringablePolicy<Sequence<?>>

Default policies for formatting Sequence objects into textual representations in form of char sequences.

Implementation notes:
Though defined as an enumeration, different applicable policies may still be applied to format sequences, i.e. any policy having the type Stringable&ltSequence<?>>.

See implementation notes for the ObjectPolicy enumeration.

Author:
Gunni Rode / rode.dk
See Also:
ObjectPolicy

Nested Class Summary
 
Nested classes/interfaces inherited from interface dk.rode.thesis.strategy.StringablePolicy
StringablePolicy.NameIdiom, StringablePolicy.Type
 
Enum Constant Summary
DEFAULT
          Generates a char sequence representation of a sequence by invoking toString() on it.
ID
          Generates a char sequence representation of a sequence having the following format: Sequence[..]
IDENTITY
          Generates a char sequence representation of a sequence having the following format: Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..]
NAME
          Generates a char sequence representation of a sequence having the following format: Sequence Where Sequence is the simple class name of the class of the sequence.
SHORT
          Generates a char sequence representation of a sequence having the following format: Sequence[..]
VALUE
          Generates a char sequence representation of a sequence having the following format: ..
VALUE_UPPERCASE
          Generates a char sequence representation of a sequence having the following format: ..
VERBOSE
          Generates a char sequence representation of a sequence having the following format: Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..; bounded: ..; consistent: ..; unique: ..; state: ..]
VERBOSE_OPEN
          Generates a char sequence (StringBuilder) representation of a sequence having the following format: Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..; bounded: ..; consistent: ..; unique: ..; state: ..
 
Method Summary
 CharSequence toString(Sequence<?> sequence)
          Returns a textual representation of the object supplied as object in form of a char sequence.
 StringablePolicy.Type type()
          Returns the type of this policy.
static SequencePolicy valueOf(String name)
          Returns the enum constant of this type with the specified name.
static SequencePolicy[] values()
          Returns an array containing the constants of this enum type, in the order they are declared.
 
Methods inherited from class java.lang.Enum
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

DEFAULT

@Participant(value="ConcreteStrategy")
public static final SequencePolicy DEFAULT
Generates a char sequence representation of a sequence by invoking toString() on it.


ID

@Participant(value="ConcreteStrategy")
public static final SequencePolicy ID
Generates a char sequence representation of a sequence having the following format:
   Sequence[..]
 
Where Sequence is the simple class name of the class of the sequence, and .. is the identity hash-code of the sequence.


IDENTITY

@Participant(value="ConcreteStrategy")
public static final SequencePolicy IDENTITY
Generates a char sequence representation of a sequence having the following format:
   Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..]
 
Where Sequence is the simple class name of the class of the sequence, and .. are the hash-code and current value of the sequence, respectively.

See Also:
ObjectPolicy.HASHCODE

NAME

@Participant(value="ConcreteStrategy")
public static final SequencePolicy NAME
Generates a char sequence representation of a sequence having the following format:
   Sequence
 
Where Sequence is the simple class name of the class of the sequence.

This policy is considered StringablePolicy.Type.CLOSED.


SHORT

@Participant(value="ConcreteStrategy")
public static final SequencePolicy SHORT
Generates a char sequence representation of a sequence having the following format:
   Sequence[..]
 
Where Sequence is the simple class name of the class of the sequence, and .. is the current sequence value.


VALUE

@Participant(value="ConcreteStrategy")
public static final SequencePolicy VALUE
Generates a char sequence representation of a sequence having the following format:
   ..
 
Where .. is the current value of the sequence.

This policy is considered StringablePolicy.Type.CLOSED.


VALUE_UPPERCASE

@Participant(value="ConcreteStrategy")
public static final SequencePolicy VALUE_UPPERCASE
Generates a char sequence representation of a sequence having the following format:
   ..
 
Where .. is the current value of the sequence as an upper-cased string.

This policy is considered StringablePolicy.Type.CLOSED.


VERBOSE

@Participant(value="ConcreteStrategy")
public static final SequencePolicy VERBOSE
Generates a char sequence representation of a sequence having the following format:
   Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..; bounded: ..; consistent: ..; unique: ..; state: ..]
 
Where Sequence is the simple class name of the class of the sequence.

See Also:
VERBOSE_OPEN, ObjectPolicy.HASHCODE

VERBOSE_OPEN

@Participant(value="ConcreteStrategy")
public static final SequencePolicy VERBOSE_OPEN
Generates a char sequence (StringBuilder) representation of a sequence having the following format:
   Sequence[hash-code: ..[; identity-hash-code: ..]; current: ..; bounded: ..; consistent: ..; unique: ..; state: .. 
 
Where Sequence is the simple class name of the class of the sequence.

The difference between this policy and VERBOSE is that the representation formatted by this policy does not end with a closing bracket (]), i.e. is StringablePolicy.Type.OPEN.

See Also:
ObjectPolicy.HASHCODE
Method Detail

toString

public CharSequence toString(Sequence<?> sequence)
Description copied from interface: StringablePolicy
Returns a textual representation of the object supplied as object in form of a char sequence.

Specified by:
toString in interface StringablePolicy<Sequence<?>>
Parameters:
sequence - The object; cannot be null.
Returns:
The char sequence representation; never null.
See Also:
ObjectPolicy.NAME

type

public StringablePolicy.Type type()
Description copied from interface: StringablePolicy
Returns the type of this policy.

The stringable context can use the type to decide how to use the textual representation of this policy in conjunction with additional text.

Specified by:
type in interface StringablePolicy<Sequence<?>>
Returns:
StringablePolicy.Type.APPENDABLE is returned unless explicitly documented otherwise for a given constant.

valueOf

public static SequencePolicy valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)

Parameters:
name - the name of the enum constant to be returned.
Returns:
the enum constant with the specified name
Throws:
IllegalArgumentException - if this enum type has no constant with the specified name
NullPointerException - if the argument is null

values

public static SequencePolicy[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
for (SequencePolicy c : SequencePolicy.values())
    System.out.println(c);

Returns:
an array containing the constants of this enum type, in the order they are declared

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.