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

dk.rode.thesis.strategy
Class StringablePolicy.NameIdiom

java.lang.Object
  extended by dk.rode.thesis.strategy.StringablePolicy.NameIdiom
Enclosing interface:
StringablePolicy<T>

public static final class StringablePolicy.NameIdiom
extends Object

An idiom that allows the retrieval of a given StringablePolicy defined as an enumeration constant based on an exact name of another, possibly unrelated, policy.

The name idiom can be used in case a given stringable type contains other stringable types that should be formatted using equivalent policies (by name) in order to supply an overall textual representation.

Author:
Gunni Rode / rode.dk

Constructor Summary
private StringablePolicy.NameIdiom()
          Private off-limit constructor.
 
Method Summary
static
<S extends Enum<S> & StringablePolicy<?>,T extends StringablePolicy<?>>
S
getSimilarByName(Class<S> type, T policy)
          Returns the policy of type S having the exact name as the toString() value of the policy supplied as policy, or null if no such constant can be found.
static
<S extends Enum<S> & StringablePolicy<?>,T extends StringablePolicy<?>>
S
getSimilarByName(Class<S> type, T policy, S defaultPolicy)
          Returns the policy of type S having the exact name as the toString() value of the policy supplied as policy, or defaultPolicy if no such constant can be found.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringablePolicy.NameIdiom

private StringablePolicy.NameIdiom()
Private off-limit constructor.

Method Detail

getSimilarByName

public static final <S extends Enum<S> & StringablePolicy<?>,T extends StringablePolicy<?>> S getSimilarByName(Class<S> type,
                                                                                                              T policy)
Returns the policy of type S having the exact name as the toString() value of the policy supplied as policy, or null if no such constant can be found.

For enumeration constants, the toString() method always returns its name.

Type Parameters:
S - The type of the policy to return.
T - The type of the policy that supplies the name to find.
Parameters:
type - The enumeration type where the desired policy is to be looked up; can be null, in which case null is returned.
policy - The policy to supply the name to look up based on its toString representation; can be null, in which case null is returned.
Returns:
A policy defined as an enumeration constant of type S having the same name as policy.toString(), or null in case no such constant can be found.
See Also:
getSimilarByName(Class, StringablePolicy, Enum)

getSimilarByName

public static final <S extends Enum<S> & StringablePolicy<?>,T extends StringablePolicy<?>> S getSimilarByName(Class<S> type,
                                                                                                              T policy,
                                                                                                              S defaultPolicy)
Returns the policy of type S having the exact name as the toString() value of the policy supplied as policy, or defaultPolicy if no such constant can be found.

For enumeration constants, the toString() method always returns its name.

Type Parameters:
S - The type of the policy to return.
T - The type of the policy that supplies the name to find.
Parameters:
type - The enumeration type where the desired policy is to be looked up; can be null, in which case defaultPolicy is returned.
policy - The policy to supply the name to look up based on its toString representation; can be null, in which case defaultPolicy is returned.
defaultPolicy - The default policy; can be null.
Returns:
A policy defined as an enumeration constant of type S having the same name as policy.toString(), or defaultPolicy in case no such constant can be found.
See Also:
getSimilarByName(Class, StringablePolicy)

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.