diff --git a/icu4j/src/com/ibm/icu/impl/ICUCharacterIterator.java b/icu4j/src/com/ibm/icu/impl/CharacterIteratorWrapper.java similarity index 89% rename from icu4j/src/com/ibm/icu/impl/ICUCharacterIterator.java rename to icu4j/src/com/ibm/icu/impl/CharacterIteratorWrapper.java index e9fdbcfc9e0..8d796b0ebab 100644 --- a/icu4j/src/com/ibm/icu/impl/ICUCharacterIterator.java +++ b/icu4j/src/com/ibm/icu/impl/CharacterIteratorWrapper.java @@ -4,7 +4,7 @@ * others. All Rights Reserved. * ******************************************************************************* * - * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Attic/ICUCharacterIterator.java,v $ + * $Source: /usr/cvs/icu4j/icu4j/src/com/ibm/icu/impl/ICUCharacterIterator.java,v $ * $Date: 2002/06/20 01:18:07 $ * $Revision: 1.1 $ * @@ -14,7 +14,13 @@ package com.ibm.icu.impl; import java.text.CharacterIterator; -public class ICUCharacterIterator extends UCharacterIterator { +/** + * This class is a wrapper around CharacterIterator and implements the + * UCharacterIterator protocol + * @author ram + */ + +public class CharacterIteratorWrapper extends UCharacterIterator { private CharacterIterator iterator; @@ -33,7 +39,7 @@ public class ICUCharacterIterator extends UCharacterIterator { */ private int beginIndex; - public ICUCharacterIterator(CharacterIterator iter){ + public CharacterIteratorWrapper(CharacterIterator iter){ if(iter==null){ throw new IllegalArgumentException(); } @@ -126,7 +132,7 @@ public class ICUCharacterIterator extends UCharacterIterator { */ public Object clone(){ try { - ICUCharacterIterator result = (ICUCharacterIterator) super.clone(); + CharacterIteratorWrapper result = (CharacterIteratorWrapper) super.clone(); result.iterator = (CharacterIterator)this.iterator.clone(); return result; } catch (CloneNotSupportedException e) { diff --git a/icu4j/src/com/ibm/icu/impl/ICULocaleService.java b/icu4j/src/com/ibm/icu/impl/ICULocaleService.java index cc6c0966ca6..3e1abae5ea5 100644 --- a/icu4j/src/com/ibm/icu/impl/ICULocaleService.java +++ b/icu4j/src/com/ibm/icu/impl/ICULocaleService.java @@ -9,7 +9,6 @@ import java.util.Map; import java.util.ResourceBundle; import java.util.Set; -import java.util.Enumeration; public class ICULocaleService extends ICUService { Locale fallbackLocale; diff --git a/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java b/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java index 33ba53f8bd0..95638128b06 100644 --- a/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java +++ b/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java @@ -5,8 +5,8 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java,v $ - * $Date: 2002/07/16 00:41:10 $ - * $Revision: 1.1 $ + * $Date: 2002/07/19 22:08:46 $ + * $Revision: 1.2 $ * ******************************************************************************* */ @@ -216,13 +216,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator { replaceable.getChars(0,length,fillIn,offset); return length; } - - public String getString(){ - char[] arr = new char[length]; - replaceable.getChars(0,length,arr,0); - return new String(arr); - } - + // private data members ---------------------------------------------------- /** diff --git a/icu4j/src/com/ibm/icu/impl/UCharacterIterator.java b/icu4j/src/com/ibm/icu/impl/UCharacterIterator.java index a211e9164f6..cf0aa864e04 100644 --- a/icu4j/src/com/ibm/icu/impl/UCharacterIterator.java +++ b/icu4j/src/com/ibm/icu/impl/UCharacterIterator.java @@ -5,15 +5,14 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Attic/UCharacterIterator.java,v $ - * $Date: 2002/07/16 18:51:59 $ - * $Revision: 1.9 $ + * $Date: 2002/07/19 22:08:45 $ + * $Revision: 1.10 $ * ******************************************************************************* */ package com.ibm.icu.impl; import com.ibm.icu.text.Replaceable; -import com.ibm.icu.text.StringCharacterIterator; import com.ibm.icu.text.UTF16; import java.text.CharacterIterator; @@ -109,7 +108,7 @@ public abstract class UCharacterIterator * @exception IllegalArgumentException if the argument is null */ public static final UCharacterIterator getInstance(CharacterIterator source){ - return new ICUCharacterIterator(source); + return new CharacterIteratorWrapper(source); } // public methods ---------------------------------------------------------- @@ -120,7 +119,7 @@ public abstract class UCharacterIterator * @return java.text.CharacterIterator object */ public CharacterIterator getCharacterIterator(){ - return new StringCharacterIterator(this.getText()); + return new UCharacterIteratorWrapper(this); } /** diff --git a/icu4j/src/com/ibm/icu/impl/UCharacterIteratorWrapper.java b/icu4j/src/com/ibm/icu/impl/UCharacterIteratorWrapper.java new file mode 100644 index 00000000000..94462d35e28 --- /dev/null +++ b/icu4j/src/com/ibm/icu/impl/UCharacterIteratorWrapper.java @@ -0,0 +1,151 @@ +/* + ******************************************************************************* + * Copyright (C) 1996-2000, International Business Machines Corporation and * + * others. All Rights Reserved. * + ******************************************************************************* + * + * $Source: /usr/cvs/icu4j/icu4j/src/com/ibm/icu/impl/ICUCharacterIterator.java,v $ + * $Date: 2002/06/20 01:18:07 $ + * $Revision: 1.1 $ + * + ******************************************************************************* + */ + +package com.ibm.icu.impl; + +import java.text.CharacterIterator; + +/** + * This class is a wrapper around UCharacterIterator and implements the + * CharacterIterator protocol + * @author ram + */ +public class UCharacterIteratorWrapper implements CharacterIterator{ + + public UCharacterIteratorWrapper(UCharacterIterator iter){ + this.iterator = iter; + this.currentIndex = 0; + this.length = iter.getLength(); + //UCharacterIterator always iterates from 0 - length + this.beginIndex = 0; + } + + private UCharacterIterator iterator; + private int currentIndex; + private int length; + private int beginIndex; + + /** + * Sets the position to getBeginIndex() and returns the character at that + * position. + * @return the first character in the text, or DONE if the text is empty + * @see #getBeginIndex() + */ + public char first(){ + iterator.setToStart(); + return (char)iterator.current(); + } + + /** + * Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty) + * and returns the character at that position. + * @return the last character in the text, or DONE if the text is empty + * @see #getEndIndex() + */ + public char last(){ + iterator.setToLimit(); + return (char)iterator.current(); + } + + /** + * Gets the character at the current position (as returned by getIndex()). + * @return the character at the current position or DONE if the current + * position is off the end of the text. + * @see #getIndex() + */ + public char current(){ + iterator.setIndex(currentIndex); + return (char) iterator.current(); + } + + /** + * Increments the iterator's index by one and returns the character + * at the new index. If the resulting index is greater or equal + * to getEndIndex(), the current index is reset to getEndIndex() and + * a value of DONE is returned. + * @return the character at the new position or DONE if the new + * position is off the end of the text range. + */ + public char next(){ + //pre-increment + iterator.setIndex(++currentIndex); + return (char) iterator.current(); + } + + /** + * Decrements the iterator's index by one and returns the character + * at the new index. If the current index is getBeginIndex(), the index + * remains at getBeginIndex() and a value of DONE is returned. + * @return the character at the new position or DONE if the current + * position is equal to getBeginIndex(). + */ + public char previous(){ + //pre-decrement + iterator.setIndex(--currentIndex); + return (char) iterator.current(); + } + + /** + * Sets the position to the specified position in the text and returns that + * character. + * @param position the position within the text. Valid values range from + * getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown + * if an invalid value is supplied. + * @return the character at the specified position or DONE if the specified position is equal to getEndIndex() + */ + public char setIndex(int position){ + currentIndex=position; + return (char) iterator.current(); + } + + /** + * Returns the start index of the text. + * @return the index at which the text begins. + */ + public int getBeginIndex(){ + return beginIndex; + } + + /** + * Returns the end index of the text. This index is the index of the first + * character following the end of the text. + * @return the index after the last character in the text + */ + public int getEndIndex(){ + return length-1; + } + + /** + * Returns the current index. + * @return the current index. + */ + public int getIndex(){ + return currentIndex; + } + + /** + * Create a copy of this iterator + * @return A copy of this + */ + public Object clone(){ + try { + UCharacterIteratorWrapper result = (UCharacterIteratorWrapper) super.clone(); + result.iterator = (UCharacterIterator)this.iterator.clone(); + return result; + } catch (CloneNotSupportedException e) { + return null; // only invoked if bad underlying character iterator + } + } + +} +