|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |
java.lang.Object java.lang.Enum<ObjectPolicy> dk.rode.thesis.strategy.ObjectPolicy
public enum ObjectPolicy
Standard policies for formatting any type of Object
into textual representations in form of char sequences (appendable)
or as strings (immutable).
Implementation notes:
Though defined as an enumeration, different applicable policies
may still be applied to format objects, i.e. any policy having
the type Stringable<Object>
.
NetBeans 5.5.1 has problems with annotated enumeration constants
in its editor. The constants are not listed when using code-completion,
merely a single @
regardless of the number of constants.
Even more so, the standard Java compiler version 1.6.0_01 (in NetBeans
5.5.1) does not allow each constant to implement interface
functionality without the interface methods being declared
(abstract) in the enumeration class it self, which Eclipse
3.3 does. Hence, the toString(Object)
method is declared
abstract here and implemented by each constant for compatibility
with the standard compiler.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface dk.rode.thesis.strategy.StringablePolicy |
---|
StringablePolicy.NameIdiom, StringablePolicy.Type |
Enum Constant Summary | |
---|---|
HASHCODE
Generates a char sequence (StringBuilder) representation of an object having the following format: hash-code: ..[; identity-hash-code: ..] |
|
ID
Generates a char sequence representation of an object having the following format. |
|
ID_OPEN
Generates a char sequence (StingBuilder) representation of an object having the following format. |
|
IDENTITY
Generates a char sequence representation of an object having the following format: Class[hash-code: ..[; identity-hash-code: ..]] |
|
IDENTITY_OPEN
Generates a char sequence (StringBuilder) representation of an object having the following format: Class[hash-code: ..[; identity-hash-code: ..] |
|
NAME
Generates a char sequence (StringBuilder) representation of an object having the following format: Class Where Class is the simple name of the class of
the object. |
|
NAME_OPEN
Generates a char sequence (StringBuilder) representation of an object having the following format: Class[ Where Class is the simple name of the class of
the object. |
Method Summary | |
---|---|
String |
asString(Object object)
Handy shortcut that returns a textual representation of the object supplied as object as a string. |
abstract CharSequence |
toString(Object object)
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 ObjectPolicy |
valueOf(String name)
Returns the enum constant of this type with the specified name. |
static ObjectPolicy[] |
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 |
---|
@Participant(value="ConcreteStrategy") public static final ObjectPolicy HASHCODE
hash-code: ..[; identity-hash-code: ..]Where
hash-code
is the hash-code of the object.
If the identity hash-code differs from
the object hash code, identity-hash-code
is the
identity hash code.
Note, that identity hash codes need still not be unique per unique object!
This policy is considered StringablePolicy.Type.OPEN
.
@Participant(value="ConcreteStrategy") public static final ObjectPolicy ID
Class[..]Where
Class
is the simple class name of the class
of the object, and ..
is the identity
hash-code of the object.
ID_OPEN
@Participant(value="ConcreteStrategy") public static final ObjectPolicy ID_OPEN
Class[..Where
Class
is the simple class name of the class
of the object, and ..
is the identity
hash-code of the object.
The difference between this policy and ID
is that the representation formatted by this policy does
not end with a closing bracket (]), i.e. this policy is
StringablePolicy.Type.OPEN
.
@Participant(value="ConcreteStrategy") public static final ObjectPolicy IDENTITY
Class[hash-code: ..[; identity-hash-code: ..]]Where
Class
is the simple class name of the class
of the object, and hash-code
is the hash-code of
the object.
If the identity hash-code differs from
the object hash code, identity-hash-code
is the
identity hash code.
IDENTITY_OPEN
@Participant(value="ConcreteStrategy") public static final ObjectPolicy IDENTITY_OPEN
Class[hash-code: ..[; identity-hash-code: ..]Where
Class
is the simple class name of the class
of the object, and hash-code
is the hash-code of
the object.
If the identity hash-code differs from
the object hash code, identity-hash-code
is the
identity hash code.
The difference between this policy and IDENTITY
is that the representation formatted by this policy does
not end with a closing bracket (]), i.e. this policy is
StringablePolicy.Type.OPEN
.
@Participant(value="ConcreteStrategy") public static final ObjectPolicy NAME
ClassWhere
Class
is the simple name of the class of
the object.
NAME_OPEN
@Participant(value="ConcreteStrategy") public static final ObjectPolicy NAME_OPEN
Class[Where
Class
is the simple name of the class of
the object.
The difference between this policy and NAME
is that the representation formatted by this policy includes
an opening bracket ([), i.e. this policy is considered
StringablePolicy.Type.OPEN
.
Method Detail |
---|
public String asString(Object object)
object
as a string.
This is typically useful for StringablePolicy.Type.CLOSED
stringable policies and/or when such a policy is applied in the standard
Object.toString()
method.
object
- The object; cannot be null.
NullPointerException
- If object
is null.toString(Object)
public abstract CharSequence toString(Object object)
object
in form of a char sequence.
toString
in interface StringablePolicy<Object>
object
- The object; cannot be null.
Stringable.toString(StringablePolicy)
public StringablePolicy.Type type()
StringablePolicy
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.
type
in interface StringablePolicy<Object>
StringablePolicy.Type.APPENDABLE
is returned unless
explicitly documented otherwise for a given constant.public static ObjectPolicy valueOf(String name)
name
- the name of the enum constant to be returned.
IllegalArgumentException
- if this enum type has no constant
with the specified name
NullPointerException
- if the argument is nullpublic static ObjectPolicy[] values()
for (ObjectPolicy c : ObjectPolicy.values()) System.out.println(c);
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | ENUM CONSTANTS | FIELD | METHOD | DETAIL: ENUM CONSTANTS | FIELD | METHOD |