• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GENERATED SOURCE. DO NOT MODIFY. */
2 // © 2016 and later: Unicode, Inc. and others.
3 // License & terms of use: http://www.unicode.org/copyright.html#License
4 /*
5  *******************************************************************************
6  * Copyright (C) 1996-2014, International Business Machines Corporation and    *
7  * others. All Rights Reserved.                                                *
8  *******************************************************************************
9  */
10 
11 
12 // NOTE:  This class is identical to java.text.StringCharacterIterator
13 // in JDK 1.2.  It's copied here because the JDK 1.1 version of
14 // StringCharacterIterator has a bug that prevents it from working
15 // right with RuleBasedBreakIterator.  This class is unnecessary
16 // when using RuleBasedBreakIterator with JDK 1.2.
17 
18 package ohos.global.icu.text;
19 import java.text.CharacterIterator;
20 
21 import ohos.global.icu.util.ICUCloneNotSupportedException;
22 
23 /**
24  * <code>StringCharacterIterator</code> implements the
25  * <code>CharacterIterater</code> protocol for a <code>String</code>.
26  * The <code>StringCharacterIterator</code> class iterates over the
27  * entire <code>String</code>.
28  *
29  * @see CharacterIterator
30  * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
31  * @hide exposed on OHOS
32  */
33 @Deprecated
34 ///CLOVER:OFF
35 public final class StringCharacterIterator implements CharacterIterator
36 {
37     private String text;
38     private int begin;
39     private int end;
40     // invariant: begin <= pos <= end
41     private int pos;
42 
43     /**
44      * Constructs an iterator with an initial index of 0.
45      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
46      */
47     @Deprecated
StringCharacterIterator(String text)48     public StringCharacterIterator(String text)
49     {
50         this(text, 0);
51     }
52 
53     /**
54      * Constructs an iterator with the specified initial index.
55      *
56      * @param  text   The String to be iterated over
57      * @param  pos    Initial iterator position
58      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
59      */
60     @Deprecated
StringCharacterIterator(String text, int pos)61     public StringCharacterIterator(String text, int pos)
62     {
63     this(text, 0, text.length(), pos);
64     }
65 
66     /**
67      * Constructs an iterator over the given range of the given string, with the
68      * index set at the specified position.
69      *
70      * @param  text   The String to be iterated over
71      * @param  begin  Index of the first character
72      * @param  end    Index of the character following the last character
73      * @param  pos    Initial iterator position
74      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
75      */
76     @Deprecated
StringCharacterIterator(String text, int begin, int end, int pos)77     public StringCharacterIterator(String text, int begin, int end, int pos) {
78         if (text == null) {
79             throw new NullPointerException();
80         }
81         this.text = text;
82 
83         if (begin < 0 || begin > end || end > text.length()) {
84             throw new IllegalArgumentException("Invalid substring range");
85         }
86 
87         if (pos < begin || pos > end) {
88             throw new IllegalArgumentException("Invalid position");
89         }
90 
91         this.begin = begin;
92         this.end = end;
93         this.pos = pos;
94     }
95 
96     /**
97      * Reset this iterator to point to a new string.  This package-visible
98      * method is used by other java.text classes that want to avoid allocating
99      * new StringCharacterIterator objects every time their setText method
100      * is called.
101      *
102      * @param  text   The String to be iterated over
103      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
104      */
105     @Deprecated
setText(String text)106     public void setText(String text) {
107         if (text == null) {
108             throw new NullPointerException();
109         }
110         this.text = text;
111         this.begin = 0;
112         this.end = text.length();
113         this.pos = 0;
114     }
115 
116     /**
117      * Implements CharacterIterator.first() for String.
118      * @see CharacterIterator#first
119      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
120      */
121     @Deprecated
first()122     public char first()
123     {
124         pos = begin;
125         return current();
126     }
127 
128     /**
129      * Implements CharacterIterator.last() for String.
130      * @see CharacterIterator#last
131      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
132      */
133     @Deprecated
last()134     public char last()
135     {
136         if (end != begin) {
137             pos = end - 1;
138         } else {
139             pos = end;
140         }
141         return current();
142      }
143 
144     /**
145      * Implements CharacterIterator.setIndex() for String.
146      * @see CharacterIterator#setIndex
147      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
148      */
149     @Deprecated
setIndex(int p)150     public char setIndex(int p)
151     {
152     if (p < begin || p > end) {
153             throw new IllegalArgumentException("Invalid index");
154     }
155         pos = p;
156         return current();
157     }
158 
159     /**
160      * Implements CharacterIterator.current() for String.
161      * @see CharacterIterator#current
162      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
163      */
164     @Deprecated
current()165     public char current()
166     {
167         if (pos >= begin && pos < end) {
168             return text.charAt(pos);
169         }
170         else {
171             return DONE;
172         }
173     }
174 
175     /**
176      * Implements CharacterIterator.next() for String.
177      * @see CharacterIterator#next
178      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
179      */
180     @Deprecated
next()181     public char next()
182     {
183         if (pos < end - 1) {
184             pos++;
185             return text.charAt(pos);
186         }
187         else {
188             pos = end;
189             return DONE;
190         }
191     }
192 
193     /**
194      * Implements CharacterIterator.previous() for String.
195      * @see CharacterIterator#previous
196      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
197      */
198     @Deprecated
previous()199     public char previous()
200     {
201         if (pos > begin) {
202             pos--;
203             return text.charAt(pos);
204         }
205         else {
206             return DONE;
207         }
208     }
209 
210     /**
211      * Implements CharacterIterator.getBeginIndex() for String.
212      * @see CharacterIterator#getBeginIndex
213      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
214      */
215     @Deprecated
getBeginIndex()216     public int getBeginIndex()
217     {
218         return begin;
219     }
220 
221     /**
222      * Implements CharacterIterator.getEndIndex() for String.
223      * @see CharacterIterator#getEndIndex
224      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
225      */
226     @Deprecated
getEndIndex()227     public int getEndIndex()
228     {
229         return end;
230     }
231 
232     /**
233      * Implements CharacterIterator.getIndex() for String.
234      * @see CharacterIterator#getIndex
235      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
236      */
237     @Deprecated
getIndex()238     public int getIndex()
239     {
240         return pos;
241     }
242 
243     /**
244      * Compares the equality of two StringCharacterIterator objects.
245      * @param obj the StringCharacterIterator object to be compared with.
246      * @return true if the given obj is the same as this
247      * StringCharacterIterator object; false otherwise.
248      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
249      */
250     @Deprecated
equals(Object obj)251     public boolean equals(Object obj)
252     {
253         if (this == obj) {
254             return true;
255         }
256         if (!(obj instanceof StringCharacterIterator)) {
257             return false;
258         }
259 
260         StringCharacterIterator that = (StringCharacterIterator) obj;
261 
262         if (hashCode() != that.hashCode()) {
263             return false;
264         }
265         if (!text.equals(that.text)) {
266             return false;
267         }
268         if (pos != that.pos || begin != that.begin || end != that.end) {
269             return false;
270         }
271         return true;
272     }
273 
274     /**
275      * Computes a hashcode for this iterator.
276      * @return A hash code
277      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
278      */
279     @Deprecated
hashCode()280     public int hashCode()
281     {
282         return text.hashCode() ^ pos ^ begin ^ end;
283     }
284 
285     /**
286      * Creates a copy of this iterator.
287      * @return A copy of this
288      * @deprecated ICU 2.4. Use java.text.StringCharacterIterator instead.
289      */
290     @Deprecated
clone()291     public Object clone()
292     {
293         try {
294             StringCharacterIterator other
295             = (StringCharacterIterator) super.clone();
296             return other;
297         }
298         catch (CloneNotSupportedException e) {
299             throw new ICUCloneNotSupportedException(e);
300         }
301     }
302 
303 }
304 ///CLOVER:ON
305