org.nakedobjects.applib.util
Class TitleBuffer

java.lang.Object
  extended by org.nakedobjects.applib.util.TitleBuffer

public class TitleBuffer
extends Object

Title buffer is a utility class to help produce titles for objects without having to add lots of guard code. It provides two basic method: one to concatenate a title to the buffer; another to append a title with a joiner string, taking care adding in necessary spaces. The benefits of using this class is that null references are safely ignored (rather than appearing as 'null'), and joiners (a space by default) are only added when needed.


Constructor Summary
TitleBuffer()
          Creates a new, empty, title object.
TitleBuffer(Object object)
          Creates a new title object, containing the title of the specified object.
TitleBuffer(Object object, String defaultTitle)
          Creates a new title object, containing the title of the specified object.
TitleBuffer(String text)
          Creates a new title object, containing the specified text.
 
Method Summary
 TitleBuffer append(int number)
           
 TitleBuffer append(Object object)
          Append the title of the specified object.
 TitleBuffer append(Object object, String defaultValue)
          Appends the title of the specified object, or the specified text if the objects title is null or empty.
 TitleBuffer append(String text)
          Appends a space (if there is already some text in this title object) and then the specified text.
 TitleBuffer append(String joiner, Object object)
          Appends the joining string and the title of the specified object (from its toString method).
 TitleBuffer append(String joiner, Object object, String defaultTitle)
          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 TitleString object.
 TitleBuffer append(String joiner, String text)
          Appends the joiner text, a space, and the text to the text of this TitleString object.
 TitleBuffer appendSpace()
          Append a space to the text of this TitleString 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.
 TitleBuffer concat(Object object)
          Concatenate the the title value (the result of calling an objects label() method) to this TitleString object.
 TitleBuffer concat(Object object, String defaultValue)
          Concatenate the the title value (the result of calling an objects label() method), or the specified default value if the title is equal to null or is empty, to this TitleString object.
 TitleBuffer concat(String text)
          Concatenate the specified text on to the end of the text of this TitleString.
 TitleBuffer concat(String joiner, Object object)
           
 TitleBuffer concat(String joiner, Object object, String defaultValue)
           
static boolean isEmpty(Object object)
          Determines if the specified object's title (from its toString method) is empty.
static boolean isEmpty(String text)
          Determines if the specified text is empty.
 String toString()
          Returns a String that represents the value of this object.
 TitleBuffer 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

TitleBuffer

public TitleBuffer()
Creates a new, empty, title object.


TitleBuffer

public TitleBuffer(Object object)
Creates a new title object, containing the title of the specified object.


TitleBuffer

public TitleBuffer(Object object,
                   String defaultTitle)
Creates a new title object, containing the title of the specified object.


TitleBuffer

public TitleBuffer(String text)
Creates a new title object, containing the specified text.

Method Detail

isEmpty

public static boolean isEmpty(Object object)
Determines if the specified object's title (from its toString method) is empty. Will return true if either: the specified reference is null; the object's toString method returns null; or if the toString returns an empty string.


isEmpty

public static boolean isEmpty(String text)
Determines if the specified text is empty. Will return true if either: the specified reference is null; or if the reference is an empty string.


append

public TitleBuffer append(int number)

append

public TitleBuffer append(Object object)
Append the title of the specified object.


append

public TitleBuffer append(Object object,
                          String defaultValue)
Appends the title of the specified object, or the specified text if the objects title is null or empty. Prepends a space if there is already some text in this title object.

Parameters:
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 or empty.
Returns:
a reference to the called object (itself).

append

public TitleBuffer append(String text)
Appends a space (if there is already some text in this title object) and then the specified text.

Returns:
a reference to the called object (itself).

append

public TitleBuffer append(String joiner,
                          Object object)
Appends the joining string and the title of the specified object (from its toString method). If the object is empty then nothing will be appended.

See Also:
isEmpty(Object)

append

public TitleBuffer append(String joiner,
                          Object object,
                          String defaultTitle)
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 TitleString 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.

Parameters:
joiner - text to append before the title
object - object whose title needs to be appended
defaultTitle - the text to use if the the object's title is null.
Returns:
a reference to the called object (itself).

append

public TitleBuffer append(String joiner,
                          String text)
Appends the joiner text, a space, and the text to the text of this TitleString object. If no text yet exists in the object then the joiner text and space are omitted.

Returns:
a reference to the called object (itself).

appendSpace

public TitleBuffer appendSpace()
Append a space to the text of this TitleString 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.

Returns:
a reference to the called object (itself).

concat

public final TitleBuffer concat(Object object)
Concatenate the the title value (the result of calling an objects label() method) to this TitleString object. If the value is null the no text is added.

Parameters:
object - the naked object to get a title from
Returns:
a reference to the called object (itself).

concat

public final TitleBuffer concat(Object object,
                                String defaultValue)
Concatenate the the title value (the result of calling an objects label() method), or the specified default value if the title is equal to null or is empty, to this TitleString object.

Parameters:
object - the naked object to get a title from
defaultValue - the default text to use when the naked object is null
Returns:
a reference to the called object (itself).

concat

public final TitleBuffer concat(String text)
Concatenate the specified text on to the end of the text of this TitleString.

Parameters:
text - text to append
Returns:
a reference to the called object (itself).

concat

public final TitleBuffer concat(String joiner,
                                Object object)

concat

public final TitleBuffer concat(String joiner,
                                Object object,
                                String defaultValue)

toString

public String toString()
Returns a String that represents the value of this object.

Overrides:
toString in class Object

truncate

public TitleBuffer truncate(int noWords)
Truncates this title so it has a maximum number of words. Spaces are used to determine words, thus two spaces in a title will cause two words to be mistakenly identified.

Parameters:
noWords - the number of words to show
Returns:
a reference to the called object (itself).


Copyright © 2001-2009 Naked Objects Group Ltd.. All Rights Reserved.