1 package gnu.lists; 2 3 public class SubCharSeq extends SubSequence 4 implements CharSeq 5 { 6 public SubCharSeq (AbstractSequence base, int startPos, int endPos) 7 { 8 super(base, startPos, endPos); 9 } 10 11 13 public int length() 14 { 15 return size(); 16 } 17 18 public char charAt(int index) 19 { 20 if (index < 0 || index >=size()) 21 throw new IndexOutOfBoundsException (); 22 int start = base.nextIndex(ipos0); 23 return ((CharSeq) base).charAt(start + index); 24 } 25 26 28 public void getChars (int srcBegin, int srcEnd, char[] dst, int dstBegin) 29 { 30 for (int i = srcBegin; i < srcEnd; i++) 31 dst[dstBegin++] = charAt(i); 32 } 33 34 public void setCharAt(int index, char ch) 35 { 36 if (index < 0 || index >=size()) 37 throw new IndexOutOfBoundsException (); 38 int start = base.nextIndex(ipos0); 39 ((CharSeq) base).setCharAt(start + index, ch); 40 } 41 42 43 public void fill(char value) 44 { 45 int index0 = base.nextIndex(ipos0); 46 int index1 = base.nextIndex(ipos0); 47 ((CharSeq) base).fill(index0, index1, value); 48 } 49 50 public void fill(int fromIndex, int toIndex, char value) 51 { 52 int index0 = base.nextIndex(ipos0); 53 int index1 = base.nextIndex(ipos0); 54 if (fromIndex < 0 || toIndex < fromIndex || index0 + toIndex > index1) 55 throw new IndexOutOfBoundsException (); 56 ((CharSeq) base).fill(index0 + fromIndex, index0 + toIndex, value); 57 } 58 59 60 70 77 83 public void writeTo(int start, int count, java.io.Writer dest) 84 throws java.io.IOException 85 { 86 int index0 = base.nextIndex(ipos0); 87 int index1 = base.nextIndex(ipos0); 88 if (start < 0 || count < 0 || index0 + start + count > index1) 89 throw new IndexOutOfBoundsException (); 90 ((CharSeq) base).writeTo(index0 + start, count, dest); 91 } 92 93 public void writeTo(java.io.Writer dest) throws java.io.IOException 94 { 95 int index0 = base.nextIndex(ipos0); 96 ((CharSeq) base).writeTo(index0, size(), dest); 97 } 98 99 100 public void consume(int start, int count, Consumer out) 101 { 102 int index0 = base.nextIndex(ipos0); 103 int index1 = base.nextIndex(ipos0); 104 if (start < 0 || count < 0 || index0 + start + count > index1) 105 throw new IndexOutOfBoundsException (); 106 ((CharSeq) base).consume(index0 + start, count, out); 107 } 108 109 public String toString() 110 { 111 int sz = size(); 112 StringBuffer sbuf = new StringBuffer (sz); 113 for (int i = 0; i < sz; i++) 114 sbuf.append(charAt(i)); 115 return sbuf.toString(); 116 } 117 118 private SubCharSeq subCharSeq(int start, int end) 119 { 120 int sz = size(); 121 if (start < 0 || end < start || end > sz) 122 throw new IndexOutOfBoundsException (); 123 return new SubCharSeq(base, 124 base.createRelativePos(ipos0, start, false), 125 base.createRelativePos(ipos0, end, true)); 126 } 127 128 129 public java.util.List subList(int fromIx, int toIx) 130 { 131 return (java.util.List ) subCharSeq(fromIx, toIx); 132 } 133 134 135 136 public CharSequence subSequence(int start, int end) 137 { 138 return subCharSeq(start, end); 139 } 140 141 } 142 | Popular Tags |