TitleBuffer

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.

API

TitleBuffer.java
class TitleBuffer {
  TitleBuffer()     (1)
  TitleBuffer(Object object)     (2)
  TitleBuffer(Object object, String defaultTitle)     (3)
  TitleBuffer(String text)     (4)
  boolean isEmpty(Object object)     (5)
  boolean isEmpty(String text)     (6)
  TitleBuffer append(int number)     (7)
  TitleBuffer append(Object object)     (8)
  TitleBuffer append(Object object, String defaultValue)     (9)
  TitleBuffer append(String text)     (10)
  TitleBuffer append(String joiner, Object object)     (11)
  TitleBuffer append(String joiner, Object object, String defaultTitle)     (12)
  TitleBuffer append(String joiner, String text)     (13)
  TitleBuffer appendSpace()     (14)
  TitleBuffer concat(Object object)     (15)
  TitleBuffer concat(Object object, String defaultValue)     (16)
  TitleBuffer concat(String text)     (17)
  TitleBuffer concat(String joiner, String text)     (18)
  TitleBuffer concat(String joiner, Object object)     (19)
  TitleBuffer concat(String joiner, Object object, String defaultValue)     (20)
  String toString()     (21)
  TitleBuffer truncate(int noWords)     (22)
}
1 TitleBuffer()

Creates a new, empty, TitleBuffer .

2 TitleBuffer(Object)

Creates a new TitleBuffer , containing the title of the specified object.

3 TitleBuffer(Object, String)

Creates a new title object, containing the title of the specified object.

4 TitleBuffer(String)

Creates a new title object, containing the specified text.

5 isEmpty(Object)

Determines if the specified object’s title is empty (or null).

6 isEmpty(String)

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.

7 append(int)
8 append(Object)

Append the title of the specified object to this TitleBuffer .

9 append(Object, String)

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.

10 append(String)

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

11 append(String, Object)

Appends the joining string and the title of the specified object. If the object is empty then nothing will be appended.

12 append(String, Object, String)

Append the joiner text, a space, and the title of the specified object to the text of this TitleBuffer . 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.

13 append(String, String)

Appends the joiner text, a space, and the text to the text of this TitleBuffer . If no text yet exists in the object then the joiner text and space are omitted.

14 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.

15 concat(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.

16 concat(Object, String)

Concatenate the title of the object value or the specified default value if the title is equal to null or is empty, to this TitleBuffer .

17 concat(String)

Concatenate the specified text on to the end of the text of this TitleBuffer .

18 concat(String, String)

Concatenate the joiner text and the text to the text of this TitleBuffer object. If no text yet exists in the object then the joiner text is omitted.

19 concat(String, Object)

Concatenate the joiner text and the title of the object to the text of this TitleBuffer . If no object yet exists in the object then the joiner text is omitted.

20 concat(String, Object, String)

Concatenate the joiner text and the title of the object to the text of this TitleBuffer object. If no object yet exists in the object then defaultValue is used instead.

21 toString()

Returns a String that represents the value of this object.

22 truncate(int)

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.

Members

TitleBuffer()

Creates a new, empty, TitleBuffer .

TitleBuffer(Object)

Creates a new TitleBuffer , containing the title of the specified object.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

TitleBuffer(Object, String)

Creates a new title object, containing the title of the specified object.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

TitleBuffer(String)

Creates a new title object, containing the specified text.

isEmpty(Object)

Determines if the specified object’s title is empty (or null).

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

isEmpty(String)

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(int)

append(Object)

Append the title of the specified object to this TitleBuffer .

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

append(Object, String)

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.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

append(String)

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

append(String, Object)

Appends the joining string and the title of the specified object. If the object is empty then nothing will be appended.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

append(String, Object, String)

Append the joiner text, a space, and the title of the specified object to the text of this TitleBuffer . 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.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

append(String, String)

Appends the joiner text, a space, and the text to the text of this TitleBuffer . If no text yet exists in the object then the joiner text and space are omitted.

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.

concat(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.

concat(Object, String)

Concatenate the title of the object value or the specified default value if the title is equal to null or is empty, to this TitleBuffer .

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

concat(String)

Concatenate the specified text on to the end of the text of this TitleBuffer .

concat(String, String)

Concatenate the joiner text and the text to the text of this TitleBuffer object. If no text yet exists in the object then the joiner text is omitted.

concat(String, Object)

Concatenate the joiner text and the title of the object to the text of this TitleBuffer . If no object yet exists in the object then the joiner text is omitted.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

concat(String, Object, String)

Concatenate the joiner text and the title of the object to the text of this TitleBuffer object. If no object yet exists in the object then defaultValue is used instead.

Note: this method only obtains the title using either title() or toString() ; it doesn’t honour other mechanisms for specifying the title, such as org.apache.causeway.applib.annotation.Title annotation. If that functionality is required, first call TitleService#titleOf(Object) on the object and pass in the resultant string.

toString()

Returns a String that represents the value of this object.

truncate(int)

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.