public String title() { final TitleBuffer buf = new TitleBuffer(); buf.append(name); return buf.toString(); }
/** * Concatenate the joiner text and the title of the object to the text of * this {@link org.apache.isis.applib.util.TitleBuffer}. If no object yet exists in the object then the * joiner text is omitted. * * <p> * Note: this method only obtains the title using either <tt>title()</tt> or <tt>toString()</tt>; it doesn't * honour other mechanisms for specifying the title, such as {@link org.apache.isis.applib.annotation.Title} * annotation. If that functionality is required, first call * {@link org.apache.isis.applib.DomainObjectContainer#titleOf(Object)} on the object and pass in the resultant * string. * </p> * * @return a reference to the called object (itself). */ public final TitleBuffer concat(final String joiner, final Object object) { String title = titleFor(object); if (!isEmpty(title)) { appendJoiner(joiner); concat(title, ""); } return this; }
private void appendWithSpace(final Object object) { appendSpace(); title.append(titleFor(object)); }
/** * Appends a space (if there is already some text in this title object) and * then the specified text. * * @return a reference to the called object (itself). */ public TitleBuffer append(final String text) { if (!isEmpty(text)) { appendWithSpace(text); } return this; }
@Test public void testAppend() { t1.append(""); assertEquals("add empty string", name, t1.toString()); t1.append("Smith"); name += (" " + "Smith"); assertEquals("append simple string", name, t1.toString()); t1.append(",", ""); assertEquals("append empty string with delimiter", name, t1.toString()); t1.append(",", null); assertEquals("append null with delimiter", name, t1.toString()); t1.append(",", "Xyz Ltd."); name += (", " + "Xyz Ltd."); assertEquals("append string with delimiter", name, t1.toString()); }
@Test public void testConstructorsWithObjectWhereDefaultIsNotNeeded() { t1 = new TitleBuffer(objectWithTitle, "test"); assertEquals("ABC Co.", t1.toString()); }
/** * */ public TitleBuffer append(final int number) { append(String.valueOf(number)); return this; }
/** * Appends the joiner text, a space, and the text to the text of this * {@link org.apache.isis.applib.util.TitleBuffer}. If no text yet exists in the object then the joiner * text and space are omitted. * * @return a reference to the called object (itself). */ public TitleBuffer append(final String joiner, final String text) { if (!isEmpty(text)) { appendJoiner(joiner); appendWithSpace(text); } return this; }
/** * Appends the joining string and the title of the specified object. If the object is empty then nothing * will be appended. * * <p> * Note: this method only obtains the title using either <tt>title()</tt> or <tt>toString()</tt>; it doesn't * honour other mechanisms for specifying the title, such as {@link org.apache.isis.applib.annotation.Title} * annotation. If that functionality is required, first call * {@link org.apache.isis.applib.DomainObjectContainer#titleOf(Object)} on the object and pass in the resultant * string. * </p> * * @see #isEmpty(Object) */ public TitleBuffer append(final String joiner, final Object object) { String title = titleFor(object); if (!isEmpty(title)) { appendJoiner(joiner); appendWithSpace(title); } return this; }
/** * Concatenate the joiner text and the title of the object to the text of * this TitleString object. If no object yet exists in the object then the * joiner text is omitted. * * @return a reference to the called object (itself). */ public final TitleBuffer concat(final String joiner, final Object object) { if (!isEmpty(object)) { appendJoiner(joiner); concat(object, ""); } return this; }
/** * Creates a new title object, containing the title of the specified object. * * <p> * Note: this method only obtains the title using either <tt>title()</tt> or <tt>toString()</tt>; it doesn't * honour other mechanisms for specifying the title, such as {@link org.apache.isis.applib.annotation.Title} * annotation. If that functionality is required, first call * {@link org.apache.isis.applib.DomainObjectContainer#titleOf(Object)} on the object and pass in the resultant * string. * </p> */ public TitleBuffer(final Object object, final String defaultTitle) { this(); String title = titleFor(object); if (isEmpty(title)) { concat(defaultTitle); } else { concat(title); } }
/** * Creates a new title object, containing the specified text. */ public TitleBuffer(final String text) { this(); concat(text); }
/** * Concatenate the joiner text and the title of the object to the text of * this TitleString object. If no object yet exists in the object then * defaultValue is used instead. * * @return a reference to the called object (itself). */ public final TitleBuffer concat(final String joiner, final Object object, final String defaultValue) { if (isEmpty(object)) { appendJoiner(joiner); title.append(defaultValue); } else { appendJoiner(joiner); title.append(titleFor(object)); } return this; }
/** * Append the title of the specified object to this {@link org.apache.isis.applib.util.TitleBuffer}. * * <p> * Note: this method only obtains the title using either <tt>title()</tt> or <tt>toString()</tt>; it doesn't * honour other mechanisms for specifying the title, such as {@link org.apache.isis.applib.annotation.Title} * annotation. If that functionality is required, first call * {@link org.apache.isis.applib.DomainObjectContainer#titleOf(Object)} on the object and pass in the resultant * string. * </p> */ public TitleBuffer append(final Object object) { String title = titleFor(object); if (!isEmpty(title)) { appendWithSpace(title); } return this; }
/** * Determines if the specified object's title is empty (or null). * * <p> * Note: this method only obtains the title using either <tt>title()</tt> or <tt>toString()</tt>; it doesn't * honour other mechanisms for specifying the title, such as {@link org.apache.isis.applib.annotation.Title} * annotation. If that functionality is required, first call * {@link org.apache.isis.applib.DomainObjectContainer#titleOf(Object)} on the object and pass in the resultant * string. * </p> */ public static boolean isEmpty(final Object object) { final String title = titleFor(object); return isEmpty(title); }
/** * Concatenate the joiner text and the text to the text of this {@link org.apache.isis.applib.util.TitleBuffer} * object. If no text yet exists in the object then the joiner text is * omitted. * * @return a reference to the called object (itself). */ public TitleBuffer concat(final String joiner, final String text) { if (!isEmpty(text)) { appendJoiner(joiner); title.append(text); } return this; }
@Before public void setUp() { name = "Fred"; t1 = new TitleBuffer(name); t2 = new TitleBuffer(); companyName = "ABC Co."; objectWithTitle = new TitleTestObject(); objectWithTitle.setupTitle(companyName); objectWithNoTitle = new TitleTestObject(); objectWithEmptyTitle = new TitleTestObject(); objectWithEmptyTitle.setupTitle(""); t3 = new TitleBuffer("This is a long title"); }