RingBuffer implements CharSequence, Serializable { @Override public CharSequence subSequence(final int off, final int len) { if (len < 0 || len > buffer.length || off < 0 || off >= buffer.length) { throw new IndexOutOfBoundsException(); } int o = offset + off; o = o % buffer.length; return new RingBuffer(buffer, o, len); } 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 testSubSequence() { final RingBuffer buffer = RingBuffer.fromString("0123456789"); assertThat(buffer.subSequence(5, 3).toString()).isEqualTo("567"); assertThat(buffer.subSequence(8, 2).toString()).isEqualTo("89"); buffer.append("01234"); assertThat(buffer.toString()).isEqualTo("5678901234"); assertThat(buffer.subSequence(5, 3).toString()).isEqualTo("012"); assertThat(buffer.subSequence(8, 2).toString()).isEqualTo("34"); assertThat(buffer.subSequence(8, 5).toString()).isEqualTo("34567"); assertThatThrownBy(() -> buffer.subSequence(10, 2)).isInstanceOf(IndexOutOfBoundsException.class); assertThatThrownBy(() -> buffer.subSequence(-1, 2)).isInstanceOf(IndexOutOfBoundsException.class); assertThatThrownBy(() -> buffer.subSequence(8, 11)).isInstanceOf(IndexOutOfBoundsException.class); assertThatThrownBy(() -> buffer.subSequence(8, -1)).isInstanceOf(IndexOutOfBoundsException.class); }