@Test(expected = IllegalArgumentException.class) public void testSubSequenceStartGreaterThanEnd() throws Exception { byte[] bytes = "FOOBAR".getBytes("UTF-8"); ByteArrayCharSequence bacs = new ByteArrayCharSequence(bytes, 0, bytes.length); ByteArrayCharSequence subSequence = bacs.subSequence(1, 5); subSequence.subSequence(2, 1); }
@Override public ByteArrayCharSequence subSequence(int start, int end) { if (start < 0) throw new IllegalArgumentException("start " + start + " < 0"); if (end > length()) throw new IllegalArgumentException("end " + end + " > length " + length()); if (end < start) throw new IllegalArgumentException("end " + end + " < start " + start); return new ByteArrayCharSequence(bytes, this.start + start, this.start + end); }
ByteArrayCharSequence implements CharSequence { @Override public ByteArrayCharSequence subSequence(int start, int end) { if (start < 0) throw new IllegalArgumentException("start " + start + " < 0"); if (end > length()) throw new IllegalArgumentException("end " + end + " > length " + length()); if (end < start) throw new IllegalArgumentException("end " + end + " < start " + start); return new ByteArrayCharSequence(bytes, this.start + start, this.start + end); } }
ByteArrayCharSequence implements CharSequence { @Override public ByteArrayCharSequence subSequence(int start, int end) { if (start < 0) throw new IllegalArgumentException("start " + start + " < 0"); if (end > length()) throw new IllegalArgumentException("end " + end + " > length " + length()); if (end < start) throw new IllegalArgumentException("end " + end + " < start " + start); return new ByteArrayCharSequence(bytes, this.start + start, this.start + end); } ByteArrayCharSequence(byte[] bytes, int start, int end); }
ByteArrayCharSequence implements CharSequence { @Override public ByteArrayCharSequence subSequence(int start, int end) { if (start < 0) throw new IllegalArgumentException("start " + start + " < 0"); if (end > length()) throw new IllegalArgumentException("end " + end + " > length " + length()); if (end < start) throw new IllegalArgumentException("end " + end + " < start " + start); return new ByteArrayCharSequence(bytes, this.start + start, this.start + end); } ByteArrayCharSequence(byte[] bytes, int start, int end); @Override int length(); @Override char charAt(int index); @Override ByteArrayCharSequence subSequence(int start, int end); @Override String toString(); static byte[] toSingleByteUtf8Encoding(CharSequence charSequence); }
ByteArrayCharSequence implements CharSequence { @Override public ByteArrayCharSequence subSequence(int start, int end) { if (start < 0) throw new IllegalArgumentException("start " + start + " < 0"); if (end > length()) throw new IllegalArgumentException("end " + end + " > length " + length()); if (end < start) throw new IllegalArgumentException("end " + end + " < start " + start); return new ByteArrayCharSequence(bytes, this.start + start, this.start + end); } ByteArrayCharSequence(byte[] bytes, int start, int end); @Override int length(); @Override char charAt(int index); @Override ByteArrayCharSequence subSequence(int start, int end); @Override String toString(); static byte[] toSingleByteUtf8Encoding(CharSequence charSequence);  }