1 23 package org.archive.io; 24 25 26 32 public class CharSubSequence implements CharSequence { 33 34 CharSequence inner; 35 int start; 36 int end; 37 38 public CharSubSequence(CharSequence inner, int start, int end) { 39 if (end < start) { 40 throw new IllegalArgumentException ("Start " + start + " is > " + 41 " than end " + end); 42 } 43 44 if (end < 0 || start < 0) { 45 throw new IllegalArgumentException ("Start " + start + " or end " + 46 end + " is < 0."); 47 } 48 49 if (inner == null) { 50 throw new NullPointerException ("Passed charsequence is null."); 51 } 52 53 this.inner = inner; 54 this.start = start; 55 this.end = end; 56 } 57 58 62 public int length() { 63 return this.end - this.start; 64 } 65 66 70 public char charAt(int index) { 71 return this.inner.charAt(this.start + index); 72 } 73 74 78 public CharSequence subSequence(int begin, int finish) { 79 return new CharSubSequence(this, begin, finish); 80 } 81 82 86 public String toString() { 87 StringBuffer sb = new StringBuffer (length()); 88 for (int i = 0;i<length();i++) { 90 sb.append(charAt(i)); 91 } 92 return sb.toString(); 93 } 94 } 95 | Popular Tags |