1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/samples/delegatingwriterfinal/src-api2.0/api/CharSeq.java Sat Jun 14 09:53:06 2008 +0200
1.3 @@ -0,0 +1,56 @@
1.4 +package api;
1.5 +
1.6 +/**
1.7 + *
1.8 + * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.9 + */
1.10 +final class CharSeq implements CharSequence {
1.11 + final char[] arr;
1.12 + final int off;
1.13 + final int len;
1.14 + final int c;
1.15 +
1.16 + public CharSeq(int c) {
1.17 + this.arr = null;
1.18 + this.off = 0;
1.19 + this.len = 1;
1.20 + this.c = c;
1.21 + }
1.22 +
1.23 + public CharSeq(char[] arr, int off, int len) {
1.24 + this.arr = arr;
1.25 + this.off = off;
1.26 + this.len = len;
1.27 + this.c = -1;
1.28 + }
1.29 +
1.30 + public int length() {
1.31 + return arr == null ? 1 : len;
1.32 + }
1.33 +
1.34 + public char charAt(int index) {
1.35 + if (index < 0) {
1.36 + throw new IndexOutOfBoundsException();
1.37 + }
1.38 + if (arr == null) {
1.39 + if (index > 0) {
1.40 + throw new IndexOutOfBoundsException();
1.41 + }
1.42 + return (char)c;
1.43 + } else {
1.44 + if (index >= len) {
1.45 + throw new IndexOutOfBoundsException();
1.46 + }
1.47 + return arr[off + index];
1.48 + }
1.49 + }
1.50 +
1.51 + public CharSequence subSequence(int start, int end) {
1.52 + if (end >= this.len) {
1.53 + throw new IndexOutOfBoundsException();
1.54 + }
1.55 + char[] array = arr == null ? new char[]{ (char)c } : arr;
1.56 + return new CharSeq(array, off + start, off + end);
1.57 + }
1.58 +
1.59 +}