|
Evaluating Software Design Patterns — the "Gang of Four" patterns implemented in Java 6 |
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object dk.rode.thesis.flyweight.AbstractCharacter
@Participant(value="Flyweight") public abstract class AbstractCharacter
An abstract character implements the basic traits of
the Character
interface.
Implementation notes:
Many of the methods from CharSequence
could be implemented in
this class, but it is expected that individual sub-classes do this for
better performance. This primary concern is that hashCode
and
equals(Object)
are implemented properly to ensure correct
flyweight behaviour (when stored in collections).
The specific Textual
methods are all implemented here as
they all implicitly work on CharSequence
instances. As
Textual
implements CharSequence
, we can simply
use a reference to this
when actual string functionality
is forwarded to the Strings
utility class.
Constructor Summary | |
---|---|
protected |
AbstractCharacter()
No-arg constructor. |
Method Summary | |
---|---|
boolean |
equals(Object object)
Returns true if and only if object is a
character having the same type and value as this
character, false otherwise. |
StringablePolicy<? super Character> |
getStringablePolicy(StringablePolicy<? super Character> policy)
Always return a non-null policy: policy is not null: policy is returned. |
int |
hashCode()
Returns the hash code of this character. |
int |
indexOfIgnoreCase(CharSequence sequence,
int index,
Locale locale)
Finds the first index where sequence is present in this
textual representation from the index supplied, regardless of case,
or -1 if sequence cannot be found. |
String |
lowerCaseFirst(Locale locale)
Return the first character of this textual representation lower cased. |
CharSequence |
toString(StringablePolicy<? super Character> policy)
Returns a char sequence representation of this stringable object using the format determined by policy or the
default policy
in case policy is null. |
String |
upperCaseFirst(Locale locale)
Return the first character of this textual representation upper cased. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface java.lang.CharSequence |
---|
charAt, length, subSequence, toString |
Methods inherited from interface java.lang.Comparable |
---|
compareTo |
Constructor Detail |
---|
protected AbstractCharacter()
Method Detail |
---|
public final boolean equals(Object object)
object
is a
character having the same type and value as this
character, false otherwise.
equals
in class Object
object
- The object to test; can be null.
public StringablePolicy<? super Character> getStringablePolicy(StringablePolicy<? super Character> policy)
Stringable
policy
is not null: policy
is returned.
policy
is null: a default, non-null policy is returned.
getStringablePolicy
in interface Stringable<Character>
policy
- The supplied policy; can be null.
Stringable.toString(StringablePolicy)
public final int hashCode()
hashCode
in class Object
public int indexOfIgnoreCase(CharSequence sequence, int index, Locale locale)
Textual
sequence
is present in this
textual representation from the index supplied, regardless of case,
or -1 if sequence
cannot be found.
index
is allowed to be larger than the length of
this textual representation, in which case this method returns -1.
The supplied locale is used to perform the case conversion.
indexOfIgnoreCase
in interface Textual<Character>
sequence
- The char sequence to find; cannot be null.index
- The index to start at; cannot be negative.locale
- The locale to use; can be null, in which case
the default locale is used.
sequence
from index
,
regardless of case, or -1 if not found.public String lowerCaseFirst(Locale locale)
Textual
Note, that in some locales, shifting case of a given character may cause it to expand into more than one character! Hence, the return type is a string.
lowerCaseFirst
in interface Textual<Character>
locale
- The locale to use; can be null, in which
case the default locale is used.
public final CharSequence toString(StringablePolicy<? super Character> policy)
Stringable
policy
or the
default
policy
in case policy
is null.
In Foo
, a typical implementation of this method
could be:
public CharSequence toString(StringablePolicy<? super Foo> policy) { return this.There are two approaches to formatting this stringable object into a char sequence representation:getStringablePolicy
(policy).toString
(this); }
policy
decide the entire format,
as in the Foo
example above; or
policy
to format part of the overall
representation, for example letting this method append
certain text regardless of the policy used.
StringablePolicy.toString(Object)
method, for
example in case multiple stringable objects should be formatted
into an overall representation.
In case an implementation uses the approach from bullet 2), care
must be take to respect the policy hints
so the overall format remains meaningful.
toString
in interface Stringable<Character>
policy
- The policy to dictate the formatting; can be null, in
which case the result of toString
method
is returned.
StringablePolicy.Type
public String upperCaseFirst(Locale locale)
Textual
Note, that in some locales, shifting case of a given character may cause it to expand into more than one character! Hence, the return type is a string.
upperCaseFirst
in interface Textual<Character>
locale
- The locale to use; can be null, in which
case the default locale is used.
|
Gunni Rode / rode.dk | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |