001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.text;
019:
020: /*
021: * Default implementation of BreakIterator, wrap
022: * com.ibm.icu.text.RuleBasedBreakIterator
023: *
024: */
025: class RuleBasedBreakIterator extends BreakIterator {
026:
027: /*
028: * Wrapping construction
029: */
030: RuleBasedBreakIterator(com.ibm.icu.text.BreakIterator iterator) {
031: super (iterator);
032: }
033:
034: /*
035: * (non-Javadoc)
036: *
037: * @see java.text.BreakIterator#current()
038: */
039: @Override
040: public int current() {
041: return wrapped.current();
042: }
043:
044: /*
045: * (non-Javadoc)
046: *
047: * @see java.text.BreakIterator#first()
048: */
049: @Override
050: public int first() {
051: return wrapped.first();
052: }
053:
054: /*
055: * (non-Javadoc)
056: *
057: * @see java.text.BreakIterator#following(int)
058: */
059: @Override
060: public int following(int offset) {
061: validateOffset(offset);
062: return wrapped.following(offset);
063: }
064:
065: /*
066: * check the offset, throw exception if it is invalid
067: */
068: private void validateOffset(int offset) {
069: CharacterIterator it = wrapped.getText();
070: if (offset < it.getBeginIndex() || offset >= it.getEndIndex()) {
071: throw new IllegalArgumentException();
072: }
073: }
074:
075: /*
076: * (non-Javadoc)
077: *
078: * @see java.text.BreakIterator#getText()
079: */
080: @Override
081: public CharacterIterator getText() {
082: return wrapped.getText();
083: }
084:
085: /*
086: * (non-Javadoc)
087: *
088: * @see java.text.BreakIterator#last()
089: */
090: @Override
091: public int last() {
092: return wrapped.last();
093: }
094:
095: /*
096: * (non-Javadoc)
097: *
098: * @see java.text.BreakIterator#next()
099: */
100: @Override
101: public int next() {
102: return wrapped.next();
103: }
104:
105: /*
106: * (non-Javadoc)
107: *
108: * @see java.text.BreakIterator#next(int)
109: */
110: @Override
111: public int next(int n) {
112: return wrapped.next(n);
113: }
114:
115: /*
116: * (non-Javadoc)
117: *
118: * @see java.text.BreakIterator#previous()
119: */
120: @Override
121: public int previous() {
122: return wrapped.previous();
123: }
124:
125: /*
126: * (non-Javadoc)
127: *
128: * @see java.text.BreakIterator#setText(java.text.CharacterIterator)
129: */
130: @Override
131: public void setText(CharacterIterator newText) {
132: // call a method to check if null pointer
133: newText.current();
134: wrapped.setText(newText);
135: }
136:
137: /*
138: * (non-Javadoc)
139: *
140: * @see java.text.BreakIterator#isBoundary(int)
141: */
142: @Override
143: public boolean isBoundary(int offset) {
144: validateOffset(offset);
145: return wrapped.isBoundary(offset);
146: }
147:
148: /*
149: * (non-Javadoc)
150: *
151: * @see java.text.BreakIterator#preceding(int)
152: */
153: @Override
154: public int preceding(int offset) {
155: validateOffset(offset);
156: return wrapped.preceding(offset);
157: }
158:
159: /*
160: * (non-Javadoc)
161: *
162: * @see java.lang.Object#equals(java.lang.Object)
163: */
164: @Override
165: public boolean equals(Object o) {
166: if (!(o instanceof RuleBasedBreakIterator)) {
167: return false;
168: }
169: return wrapped.equals(((RuleBasedBreakIterator) o).wrapped);
170: }
171:
172: /*
173: * (non-Javadoc)
174: *
175: * @see java.lang.Object#toString()
176: */
177: @Override
178: public String toString() {
179: return wrapped.toString();
180: }
181:
182: /*
183: * (non-Javadoc)
184: *
185: * @see java.lang.Object#hashCode()
186: */
187: @Override
188: public int hashCode() {
189: return wrapped.hashCode();
190: }
191:
192: /*
193: * (non-Javadoc)
194: *
195: * @see java.lang.Object#clone()
196: */
197: @Override
198: public Object clone() {
199: RuleBasedBreakIterator cloned = (RuleBasedBreakIterator) super
200: .clone();
201: cloned.wrapped = (com.ibm.icu.text.RuleBasedBreakIterator) wrapped
202: .clone();
203: return cloned;
204: }
205:
206: }
|