/** {@inheritDoc} */ @Override public boolean ready() { return pos < StrBuilder.this.size(); }
/** {@inheritDoc} */ @Override public int read(final char b[], final int off, int len) { if (off < 0 || len < 0 || off > b.length || (off + len) > b.length || (off + len) < 0) { throw new IndexOutOfBoundsException(); } if (len == 0) { return 0; } if (pos >= StrBuilder.this.size()) { return -1; } if (pos + len > size()) { len = StrBuilder.this.size() - pos; } StrBuilder.this.getChars(pos, pos + len, b, off); pos += len; return len; }
/** * Appends a separator if the builder is currently non-empty. * The separator is appended using {@link #append(char)}. * <p> * This method is useful for adding a separator each time around the * loop except the first. * <pre> * for (Iterator it = list.iterator(); it.hasNext(); ) { * appendSeparator(','); * append(it.next()); * } * </pre> * Note that for this simple example, you should use * {@link #appendWithSeparators(Iterable, String)}. * * @param separator the separator to use * @return this, to enable chaining * @since 2.3 */ public StrBuilder appendSeparator(final char separator) { if (size() > 0) { append(separator); } return this; }
/** {@inheritDoc} */ @Override protected List<String> tokenize(final char[] chars, final int offset, final int count) { if (chars == null) { return super.tokenize(StrBuilder.this.buffer, 0, StrBuilder.this.size()); } return super.tokenize(chars, offset, count); }
/** * Append one of both separators to the builder * If the builder is currently empty it will append the defaultIfEmpty-separator * Otherwise it will append the standard-separator * * The separator is appended using {@link #append(char)}. * @param standard the separator if builder is not empty * @param defaultIfEmpty the separator if builder is empty * @return this, to enable chaining * @since 2.5 */ public StrBuilder appendSeparator(final char standard, final char defaultIfEmpty) { if (size() > 0) { append(standard); } else { append(defaultIfEmpty); } return this; } /**
@Test public void testAppendToCharBuffer() throws Exception { final StrBuilder sb = new StrBuilder("1234567890"); final String text = "Test "; final CharBuffer buffer = CharBuffer.allocate(sb.size() + text.length()); buffer.put(text); sb.appendTo(buffer); buffer.flip(); assertEquals("Test 1234567890", buffer.toString()); } }
assertEquals(32, sb.capacity()); assertEquals(0, sb.length()); assertEquals(0, sb.size()); assertTrue(sb.isEmpty()); assertEquals(0, sb.capacity()); assertEquals(0, sb.length()); assertEquals(0, sb.size()); assertTrue(sb.isEmpty()); assertTrue(sb.capacity() >= 32); assertEquals(0, sb.length()); assertEquals(0, sb.size()); assertTrue(sb.isEmpty()); assertTrue(sb.capacity() >= 32); assertEquals(3, sb.length()); assertEquals(3, sb.size()); assertTrue(sb.isEmpty() == false); assertTrue(sb.capacity() >= 32); assertEquals(0, sb.length()); assertEquals(0, sb.size()); assertTrue(sb.isEmpty()); assertTrue(sb.capacity() > 32); assertEquals(33, sb.length()); assertEquals(33, sb.size()); assertTrue(sb.isEmpty() == false);
/** {@inheritDoc} */ @Override public boolean ready() { return pos < StrBuilder.this.size(); }
/** {@inheritDoc} */ @Override public boolean ready() { return pos < StrBuilder.this.size(); }
/** {@inheritDoc} */ @Override public boolean ready() { return pos < StrBuilder.this.size(); }
/** {@inheritDoc} */ @Override protected List<String> tokenize(final char[] chars, final int offset, final int count) { if (chars == null) { return super.tokenize(StrBuilder.this.buffer, 0, StrBuilder.this.size()); } return super.tokenize(chars, offset, count); }
/** {@inheritDoc} */ @Override protected List<String> tokenize(final char[] chars, final int offset, final int count) { if (chars == null) { return super.tokenize(StrBuilder.this.buffer, 0, StrBuilder.this.size()); } return super.tokenize(chars, offset, count); }
/** {@inheritDoc} */ @Override protected List<String> tokenize(final char[] chars, final int offset, final int count) { if (chars == null) { return super.tokenize(StrBuilder.this.buffer, 0, StrBuilder.this.size()); } return super.tokenize(chars, offset, count); }