RingBuffer implements CharSequence, Serializable { @Override public char charAt(final int index) { if (index < 0 || index >= buffer.length) { throw new IndexOutOfBoundsException(); } int off = offset + index; off = off % buffer.length; return buffer[off]; } 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 testCharAt() { final RingBuffer buffer = RingBuffer.fromString("0123456789"); buffer.append("0123456789012345678901234567890123"); assertThat(buffer.toString()).isEqualTo("4567890123"); try { buffer.charAt(-1); fail("Should have thrown exception."); } catch (final IndexOutOfBoundsException e) { } try { buffer.charAt(buffer.length()); fail("Should have thrown exception."); } catch (final IndexOutOfBoundsException e) { } assertThat(buffer.charAt(0)).isEqualTo('4'); assertThat(buffer.charAt(1)).isEqualTo('5'); assertThat(buffer.charAt(2)).isEqualTo('6'); assertThat(buffer.charAt(3)).isEqualTo('7'); assertThat(buffer.charAt(4)).isEqualTo('8'); assertThat(buffer.charAt(5)).isEqualTo('9'); assertThat(buffer.charAt(6)).isEqualTo('0'); assertThat(buffer.charAt(7)).isEqualTo('1'); assertThat(buffer.charAt(8)).isEqualTo('2'); assertThat(buffer.charAt(9)).isEqualTo('3'); }