1 9 package javolution.xml; 10 11 import javolution.lang.Text; 12 import javolution.realtime.RealtimeObject; 13 import javolution.util.FastComparator; 14 import j2me.io.Serializable; 15 import j2me.lang.CharSequence; 16 17 30 public final class CharacterData extends RealtimeObject implements 31 Serializable, CharSequence { 32 33 36 private static final Factory FACTORY = new Factory() { 37 protected Object create() { 38 return new CharacterData(); 39 } 40 protected void cleanup(Object obj) { 41 CharacterData charData = (CharacterData) obj; 42 charData._csq = null; 43 } 44 }; 45 46 49 private CharSequence _csq; 50 51 54 private CharacterData() { 55 } 56 57 63 public static CharacterData valueOf(CharSequence csq) { 64 CharacterData charData = (CharacterData) FACTORY.object(); 65 charData._csq = csq; 66 return charData; 67 } 68 69 74 public int length() { 75 return _csq.length(); 76 } 77 78 86 public char charAt(int index) { 87 return _csq.charAt(index); 88 } 89 90 99 public CharSequence subSequence(int start, int end) { 100 return CharacterData.valueOf(_csq.subSequence(start, end)); 101 } 102 103 112 public final boolean equals(Object obj) { 113 if (this == obj) 114 return true; 115 if (!(obj instanceof CharacterData)) 116 return false; 117 final CharacterData that = (CharacterData) obj; 118 return FastComparator.LEXICAL.areEqual(this._csq, that._csq); 119 } 120 121 126 public final int hashCode() { 127 return FastComparator.LEXICAL.hashCodeOf(this._csq); 128 } 129 130 141 public void getChars(int start, int end, char dest[], int destPos) { 142 if ((end > _csq.length()) || (end < start)) 143 throw new IndexOutOfBoundsException(); 144 for (int i = start, j = destPos; i < end;) { 145 dest[j++] = _csq.charAt(i++); 146 } 147 } 148 149 public Text toText() { 151 return Text.valueOf(_csq); 152 } 153 154 } | Popular Tags |