/** * Appends the text in this object into the given {@link StringBuilder}. * @param buffer the destination {@link StringBuilder} * @return the appended {@link StringBuilder} * @throws NullPointerException if this object represents {@code null} * @since 0.9.1 */ public StringBuilder appendTo(StringBuilder buffer) { if (nullValue) { throw new NullPointerException(); } StringOptionUtil.append(buffer, this); return buffer; }
/** * Appends the text in the second {@link StringOption} into the first one. * This directly modifies the first {@link StringOption}. * @param target the append target * @param contents the text contents to be appended * @throws NullPointerException if the {@link StringOption} is/represents {@code null} */ public static void append(StringOption target, String contents) { Text buffer = StringOption.BUFFER_POOL.get(); buffer.set(contents); append(target, buffer); }
@Override protected void doWrite(StringOption property, ValueWriter writer) throws IOException { buffer.setLength(0); StringOptionUtil.append(buffer, property); writer.writeString(buffer); }
/** * Appends the text in the second {@link StringOption} into the first one. * This directly modifies the first {@link StringOption}. * @param target the append target * @param contents the text contents to be appended * @throws NullPointerException if the {@link StringOption} is/represents {@code null} */ public static void append(StringOption target, StringOption contents) { Text text = contents.get(); append(target, text); }
/** * append - string builder. */ @Test public void append_string_builder() { StringBuilder buf = new StringBuilder(); buf.append("<"); StringOptionUtil.append(buf, new StringOption("Hello, world!")); buf.append(">"); assertThat(buf.toString(), is("<Hello, world!>")); }
/** * append - string. */ @Test public void append_string() { StringOption value = new StringOption("Hello"); StringOptionUtil.append(value, ", world!"); StringOptionUtil.trim(value); assertThat(value, is(new StringOption("Hello, world!"))); }
/** * append - string option. */ @Test public void append_option() { StringOption value = new StringOption("Hello"); StringOptionUtil.append(value, new StringOption(", world!")); StringOptionUtil.trim(value); assertThat(value, is(new StringOption("Hello, world!"))); }