1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18// BEGIN android-note
19// The icu implementation used was changed from icu4j to icu4jni.
20// END android-note
21
22package java.text;
23
24/*
25 * Default implementation of BreakIterator, wrap
26 * com.ibm.icu4jni.text.RuleBasedBreakIterator
27 *
28 */
29class RuleBasedBreakIterator extends BreakIterator {
30
31    /*
32     * Wrapping construction
33     */
34    RuleBasedBreakIterator(com.ibm.icu4jni.text.BreakIterator iterator) {
35        super(iterator);
36    }
37
38    /*
39     * (non-Javadoc)
40     *
41     * @see java.text.BreakIterator#current()
42     */
43    @Override
44    public int current() {
45        return wrapped.current();
46    }
47
48    /*
49     * (non-Javadoc)
50     *
51     * @see java.text.BreakIterator#first()
52     */
53    @Override
54    public int first() {
55        return wrapped.first();
56    }
57
58    /*
59     * (non-Javadoc)
60     *
61     * @see java.text.BreakIterator#following(int)
62     */
63    @Override
64    public int following(int offset) {
65        validateOffset(offset);
66        return wrapped.following(offset);
67    }
68
69    /*
70     * check the offset, throw exception if it is invalid
71     */
72    private void validateOffset(int offset) {
73        CharacterIterator it = wrapped.getText();
74        if (offset < it.getBeginIndex() || offset >= it.getEndIndex()) {
75            throw new IllegalArgumentException();
76        }
77    }
78
79    /*
80     * (non-Javadoc)
81     *
82     * @see java.text.BreakIterator#getText()
83     */
84    @Override
85    public CharacterIterator getText() {
86        return wrapped.getText();
87    }
88
89    /*
90     * (non-Javadoc)
91     *
92     * @see java.text.BreakIterator#last()
93     */
94    @Override
95    public int last() {
96        return wrapped.last();
97    }
98
99    /*
100     * (non-Javadoc)
101     *
102     * @see java.text.BreakIterator#next()
103     */
104    @Override
105    public int next() {
106        return wrapped.next();
107    }
108
109    /*
110     * (non-Javadoc)
111     *
112     * @see java.text.BreakIterator#next(int)
113     */
114    @Override
115    public int next(int n) {
116        return wrapped.next(n);
117    }
118
119    /*
120     * (non-Javadoc)
121     *
122     * @see java.text.BreakIterator#previous()
123     */
124    @Override
125    public int previous() {
126        return wrapped.previous();
127    }
128
129    /*
130     * (non-Javadoc)
131     *
132     * @see java.text.BreakIterator#setText(java.text.CharacterIterator)
133     */
134    @Override
135    public void setText(CharacterIterator newText) {
136        // call a method to check if null pointer
137        newText.current();
138        wrapped.setText(newText);
139    }
140
141    /*
142     * (non-Javadoc)
143     *
144     * @see java.text.BreakIterator#isBoundary(int)
145     */
146    @Override
147    public boolean isBoundary(int offset) {
148        validateOffset(offset);
149        return wrapped.isBoundary(offset);
150    }
151
152    /*
153     * (non-Javadoc)
154     *
155     * @see java.text.BreakIterator#preceding(int)
156     */
157    @Override
158    public int preceding(int offset) {
159        validateOffset(offset);
160        return wrapped.preceding(offset);
161    }
162
163    /*
164     * (non-Javadoc)
165     *
166     * @see java.lang.Object#equals(java.lang.Object)
167     */
168    @Override
169    public boolean equals(Object o) {
170        if (!(o instanceof RuleBasedBreakIterator)) {
171            return false;
172        }
173        return wrapped.equals(((RuleBasedBreakIterator) o).wrapped);
174    }
175
176    /*
177     * (non-Javadoc)
178     *
179     * @see java.lang.Object#toString()
180     */
181    @Override
182    public String toString() {
183        return wrapped.toString();
184    }
185
186    /*
187     * (non-Javadoc)
188     *
189     * @see java.lang.Object#hashCode()
190     */
191    @Override
192    public int hashCode() {
193        return wrapped.hashCode();
194    }
195
196    /*
197     * (non-Javadoc)
198     *
199     * @see java.lang.Object#clone()
200     */
201    @Override
202    public Object clone() {
203        RuleBasedBreakIterator cloned = (RuleBasedBreakIterator) super.clone();
204        cloned.wrapped = (com.ibm.icu4jni.text.RuleBasedBreakIterator) wrapped
205                .clone();
206        return cloned;
207    }
208
209}
210