@Test public void testSubstring() { final CharArrayBuffer buffer = new CharArrayBuffer(16); buffer.append(" name: value "); Assert.assertEquals(5, buffer.indexOf(':')); Assert.assertEquals(" name", buffer.substring(0, 5)); Assert.assertEquals(" value ", buffer.substring(6, buffer.length())); Assert.assertEquals("name", buffer.substringTrimmed(0, 5)); Assert.assertEquals("value", buffer.substringTrimmed(6, buffer.length())); Assert.assertEquals("", buffer.substringTrimmed(13, buffer.length())); }
public String substring(final int beginIndex, final int endIndex) { if (beginIndex < 0) { throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex); } if (endIndex > this.len) { throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len); } if (beginIndex > endIndex) { throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex); } return new String(this.array, beginIndex, endIndex - beginIndex); }
CharArrayBuffer implements CharSequence, Serializable { public String substring(final int beginIndex, final int endIndex) { if (beginIndex < 0) { throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex); } if (endIndex > this.len) { throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len); } if (beginIndex > endIndex) { throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex); } return new String(this.array, beginIndex, endIndex - beginIndex); } }
CharArrayBuffer implements CharSequence, Serializable { public String substring(final int beginIndex, final int endIndex) { if (beginIndex < 0) { throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex); } if (endIndex > this.len) { throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len); } if (beginIndex > endIndex) { throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex); } return new String(this.array, beginIndex, endIndex - beginIndex); } CharArrayBuffer(final int capacity); }
CharArrayBuffer implements CharSequence, Serializable { public String substring(final int beginIndex, final int endIndex) { if (beginIndex < 0) { throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex); } if (endIndex > this.len) { throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len); } if (beginIndex > endIndex) { throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex); } return new String(this.array, beginIndex, endIndex - beginIndex); } CharArrayBuffer(final int capacity); void append(final char[] b, final int off, final int len); void append(final String str); void append(final CharArrayBuffer b, final int off, final int len); void append(final CharArrayBuffer b); void append(final char ch); void append(final byte[] b, final int off, final int len); void append(final ByteArrayBuffer b, final int off, final int len); void append(final Object obj); void clear(); char[] toCharArray(); @Override char charAt(final int i); char[] array(); int capacity(); @Override int length(); void ensureCapacity(final int required); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final int ch, final int from, final int to); int indexOf(final int ch); String substring(final int beginIndex, final int endIndex); String substringTrimmed(final int beginIndex, final int endIndex); @Override CharSequence subSequence(final int beginIndex, final int endIndex); @Override String toString(); }
CharArrayBuffer implements CharSequence, Serializable { public String substring(final int beginIndex, final int endIndex) { if (beginIndex < 0) { throw new IndexOutOfBoundsException("Negative beginIndex: " + beginIndex); } if (endIndex > this.len) { throw new IndexOutOfBoundsException("endIndex: " + endIndex + " > length: " + this.len); } if (beginIndex > endIndex) { throw new IndexOutOfBoundsException("beginIndex: " + beginIndex + " > endIndex: " + endIndex); } return new String(this.array, beginIndex, endIndex - beginIndex); } CharArrayBuffer(final int capacity); void append(final char[] b, final int off, final int len); void append(final String str); void append(final CharArrayBuffer b, final int off, final int len); void append(final CharArrayBuffer b); void append(final char ch); void append(final byte[] b, final int off, final int len); void append(final ByteArrayBuffer b, final int off, final int len); void append(final Object obj); void clear(); char[] toCharArray(); @Override char charAt(final int i); char[] array(); int capacity(); @Override int length(); void ensureCapacity(final int required); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final int ch, final int from, final int to); int indexOf(final int ch); String substring(final int beginIndex, final int endIndex); String substringTrimmed(final int beginIndex, final int endIndex); @Override CharSequence subSequence(final int beginIndex, final int endIndex); @Override String toString();  }