RingBuffer implements CharSequence, Serializable { @Override public int length() { return length; } RingBuffer();  RingBuffer(final int initialSize); private  RingBuffer(final char[] buffer, final int off, final int len); static RingBuffer fromString(final String string); RingBuffer append(final char c); RingBuffer append(final char[] ch, int start, int len); RingBuffer append(final String string); RingBuffer append(final Object obj); void clear(); RingBuffer trimStart(); RingBuffer trimEnd(); RingBuffer trim(); void removeEnd(final int len); void removeStart(final int len); void setLength(final int len); boolean isEmpty(); boolean isBlank(); @Override String toString(); @Override char charAt(final int index); @Override int length(); int capacity(); @Override CharSequence subSequence(final int off, final int len); RingBuffer unsafeCopy(); RingBuffer copy(); char[] toCharArray(); void pad(final int num, final char c); void move(int increment); @Override boolean equals(final Object other); @Override int hashCode();  }
@Test void testLength() { final RingBuffer buffer = RingBuffer.fromString("0123456789"); assertThat(buffer.length()).isEqualTo(10); buffer.setLength(5); assertThat(buffer.length()).isEqualTo(5); assertThat(buffer.toString()).isEqualTo("01234"); buffer.append("999"); assertThat(buffer.length()).isEqualTo(8); assertThat(buffer.toString()).isEqualTo("01234999"); buffer.append("6667"); assertThat(buffer.length()).isEqualTo(10); assertThat(buffer.toString()).isEqualTo("2349996667"); buffer.setLength(5); assertThat(buffer.length()).isEqualTo(5); assertThat(buffer.toString()).isEqualTo("23499"); buffer.setLength(10); assertThat(buffer.length()).isEqualTo(10); assertThat(buffer.toString()).isEqualTo("2349996667"); try { buffer.setLength(-1); fail("You cannot set the length of a buffer less than 0"); } catch (final IndexOutOfBoundsException e) { } try { buffer.setLength(11); fail("You cannot set the length of a buffer greater than the buffer size"); } catch (final IndexOutOfBoundsException e) { } }