|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.nakedobjects.object.Title
Title objects are used to create title strings for labelling and titling object. This usually involves the titles of contained objects and as this are often null lots of checking and concatenation of spaces is required. This utility class simplifies the process by taken care of these issues.
Two basic methods are provided concat and append. Concat appends the specified text or text from a title to the immediate end of the text held by the object. Append starts of by appended a space if required (there is already existing text) and then the specified text or text from a title. Each of these methods return the called object reference so the method can be chained together.
The following code serves as an example.
TextString name = new TextString("Fred Smith"); TextString addr = new TextString("Larch Road"); TextString addr2 = new TextString(); NakedObject lot = null; System.out.println(new Title(name)); //append System.out.println(new Title().append(name)); System.out.println(new Title("Name:").append(name)); System.out.println(new Title(name).append(",", addr)); System.out.println(name.title().append(",", addr)); System.out.println(new Title(name).append(",", addr).append(",", addr2)); System.out.println(new Title(name).append(" Lot:", lot, "none")); //concat System.out.println(new Title("Name:").concat(name)); System.out.println(new Title(name).concat(" & ").concat(lot, "none")); System.out.println(new Title(name).concat(",").concat(addr));
And produces the following output:-
Fred Smith Fred Smith Name: Fred Smith Fred Smith, Larch Road Fred Smith, Larch Road Fred Smith, Larch Road Fred Smith Lot: none Name:Fred Smith Fred Smith & none Fred Smith,Larch Road
Constructor Summary | |
Title()
Creates a new Title objects with no text in it. |
|
Title(Naked object)
Create a new Title object containing the title of the specified object. |
|
Title(Naked object,
java.lang.String defaultValue)
Create a new Title object containing the title of the specified object or the default text if the object reference is null |
|
Title(java.lang.String text)
Create a new Title object containing the specified text. |
Method Summary | |
Title |
append(int number)
|
Title |
append(Naked object)
Appends the title text of the specified object. |
Title |
append(Naked object,
java.lang.String defaultValue)
Appends the title of the specified object, or the specified text if the objects title is null, and prepends a space if there is already some text in this title object. |
Title |
append(java.lang.String text)
Appends a space (if there is already some text in this title object) and then the specified text. |
Title |
append(java.lang.String joiner,
Naked object)
Append the joiner text, a space, and the title of the specified naked object
(object ) (got by calling the objects title() method) to
the text of this Title object. |
Title |
append(java.lang.String joiner,
Naked object,
java.lang.String defaultValue)
Append the joiner text, a space, and the title of the specified naked object
(object ) (got by calling the objects title() method) to
the text of this Title object. |
Title |
append(java.lang.String joiner,
java.lang.String text)
Appends the joiner text, a space, and the text to the text of this Title object. |
Title |
appendSpace()
Append a space to the text of this Title object if, and only if, there is some existing text i.e., a space is only added to existing text and will not create a text entry consisting of only one space. |
Title |
concat(Naked object)
Concatenate the the title value (the result of calling an objects title() method) to this Title object. |
Title |
concat(Naked object,
java.lang.String defaultValue)
Concatenate the the title value (the result of calling an objects title() method), or the specified default value if the title is equal to null or is empty, to this Title object. |
Title |
concat(java.lang.String text)
Concatenate the specified text on to the end of the text of this Title. |
Title |
concat(java.lang.String joiner,
Naked object)
|
Title |
concat(java.lang.String joiner,
Naked object,
java.lang.String defaultValue)
|
java.lang.String |
toString()
Returns a String that represents the value of this object. |
Title |
truncate(int noWords)
Truncates this title so it has a maximum number of words. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Title()
public Title(java.lang.String text)
text
- for the title to contain.public Title(Naked object)
object
- the object who's title text to copypublic Title(Naked object, java.lang.String defaultValue)
object
- the object who's title is to be used.defaultValue
- text for the title to be set to if the former parameter is null.Method Detail |
public Title append(int number)
public Title append(java.lang.String text)
public Title append(java.lang.String joiner, java.lang.String text)
public Title append(java.lang.String joiner, Naked object)
joiner
text, a space, and the title of the specified naked object
(object
) (got by calling the objects title() method) to
the text of this Title object. If the title of the specified object is null then
use the defaultValue
text.
joiner
- text to append before the titleobject
- object whose title needs to be appended
public Title append(java.lang.String joiner, Naked object, java.lang.String defaultValue)
joiner
text, a space, and the title of the specified naked object
(object
) (got by calling the objects title() method) to
the text of this Title object. If the title of the specified object is null then use the defaultValue
text.
If both the objects title and the default value are null or equate to a zero-length string then no text will be appended
; not even the joiner text.
joiner
- text to append before the titleobject
- object whose title needs to be appendeddefaultValue
- the text to use if the the object's title is null.
public Title append(Naked object)
object
or object.title()
is
null
or the object.title().toString()
returns an empty string then nothing will
be appended.
object
- the object whose we want to append to this title object.
public Title append(Naked object, java.lang.String defaultValue)
object
- the object whose title is to be appended to this title.defaultValue
- a textual value to be used if the object's title is null.
public Title appendSpace()
public final Title concat(java.lang.String text)
text
- text to append
public final Title concat(java.lang.String joiner, Naked object)
public final Title concat(Naked object)
object
- the naked object to get a title from
public final Title concat(java.lang.String joiner, Naked object, java.lang.String defaultValue)
public final Title concat(Naked object, java.lang.String defaultValue)
object
- the naked object to get a title fromdefaultValue
- the default text to use when the naked object is null
public java.lang.String toString()
public Title truncate(int noWords)
noWords
- the number of words to show
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |