ICU-1999 update the wrappers with Mark's comments
X-SVN-Rev: 10025
This commit is contained in:
parent
4b930f6d8b
commit
d9a3afd440
@ -24,27 +24,18 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
|
||||
private CharacterIterator iterator;
|
||||
|
||||
/**
|
||||
* length
|
||||
*/
|
||||
private int length;
|
||||
|
||||
public CharacterIteratorWrapper(CharacterIterator iter){
|
||||
if(iter==null){
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
iterator = iter;
|
||||
length = iter.getEndIndex() - iter.getBeginIndex();
|
||||
iterator = iter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UCharacterIterator#current()
|
||||
*/
|
||||
public int current() {
|
||||
/* if (currentIndex < length) {
|
||||
return iterator.setIndex(beginIndex + currentIndex);
|
||||
}
|
||||
*/
|
||||
int c = iterator.current();
|
||||
if(c==iterator.DONE){
|
||||
return DONE;
|
||||
@ -56,14 +47,13 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* @see UCharacterIterator#getLength()
|
||||
*/
|
||||
public int getLength() {
|
||||
return length;
|
||||
return (iterator.getEndIndex() - iterator.getBeginIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UCharacterIterator#getIndex()
|
||||
*/
|
||||
public int getIndex() {
|
||||
//return currentIndex;
|
||||
return iterator.getIndex();
|
||||
}
|
||||
|
||||
@ -71,11 +61,6 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* @see UCharacterIterator#next()
|
||||
*/
|
||||
public int next() {
|
||||
/*if(currentIndex < length){
|
||||
return iterator.setIndex(beginIndex + currentIndex++);
|
||||
}
|
||||
return DONE;
|
||||
*/
|
||||
int i = iterator.current();
|
||||
iterator.next();
|
||||
if(i==iterator.DONE){
|
||||
@ -88,11 +73,6 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* @see UCharacterIterator#previous()
|
||||
*/
|
||||
public int previous() {
|
||||
/*if(currentIndex>0){
|
||||
return iterator.setIndex(beginIndex + --currentIndex);
|
||||
}
|
||||
return DONE;
|
||||
*/
|
||||
int i = iterator.previous();
|
||||
if(i==iterator.DONE){
|
||||
return DONE;
|
||||
@ -104,11 +84,6 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* @see UCharacterIterator#setIndex(int)
|
||||
*/
|
||||
public void setIndex(int index) {
|
||||
/*if (index < 0 || index > length) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
currentIndex = index;
|
||||
*/
|
||||
try{
|
||||
iterator.setIndex(index);
|
||||
}catch(IllegalArgumentException e){
|
||||
@ -120,13 +95,14 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
* @see UCharacterIterator#setToLimit()
|
||||
*/
|
||||
public void setToLimit() {
|
||||
iterator.setIndex(length);
|
||||
iterator.setIndex(iterator.getEndIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UCharacterIterator#getText(char[])
|
||||
*/
|
||||
public int getText(char[] fillIn, int offset){
|
||||
int length =iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int currentIndex = iterator.getIndex();
|
||||
if(offset < 0 || offset + length > fillIn.length){
|
||||
throw new IndexOutOfBoundsException(Integer.toString(length));
|
||||
@ -157,8 +133,9 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
|
||||
/**
|
||||
* @see UCharacterIterator#moveIndex()
|
||||
*/
|
||||
public int moveIndex(int index){
|
||||
int idx = iterator.getIndex()+index;
|
||||
public int moveIndex(int delta){
|
||||
int length = iterator.getEndIndex() - iterator.getBeginIndex();
|
||||
int idx = iterator.getIndex()+delta;
|
||||
|
||||
if(idx < 0) {
|
||||
idx = 0;
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java,v $
|
||||
* $Date: 2002/07/31 03:04:28 $
|
||||
* $Revision: 1.3 $
|
||||
* $Date: 2002/10/11 23:43:20 $
|
||||
* $Revision: 1.4 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -40,7 +40,6 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
this.replaceable = replaceable;
|
||||
this.currentIndex = 0;
|
||||
this.length = replaceable.length();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +52,6 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
this.replaceable = new ReplaceableString(str);
|
||||
this.currentIndex = 0;
|
||||
this.length = replaceable.length();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -66,7 +64,6 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
}
|
||||
this.replaceable = new ReplaceableString(buf);
|
||||
this.currentIndex = 0;
|
||||
this.length = replaceable.length();
|
||||
}
|
||||
|
||||
// public methods ----------------------------------------------------------
|
||||
@ -89,7 +86,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
* @return current UTF16 character
|
||||
*/
|
||||
public int current(){
|
||||
if (currentIndex < length) {
|
||||
if (currentIndex < replaceable.length()) {
|
||||
return replaceable.charAt(currentIndex);
|
||||
}
|
||||
return DONE;
|
||||
@ -129,7 +126,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
* @return length of the text
|
||||
*/
|
||||
public int getLength(){
|
||||
return length;
|
||||
return replaceable.length();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -149,7 +146,7 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
* end of the text range.
|
||||
*/
|
||||
public int next(){
|
||||
if (currentIndex < length) {
|
||||
if (currentIndex < replaceable.length()) {
|
||||
return replaceable.charAt(currentIndex++);
|
||||
}
|
||||
return DONE;
|
||||
@ -182,13 +179,14 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
* currentIndex is equal to the end of the text.
|
||||
*/
|
||||
public void setIndex(int currentIndex) throws IndexOutOfBoundsException{
|
||||
if (currentIndex < 0 || currentIndex > length) {
|
||||
if (currentIndex < 0 || currentIndex > replaceable.length()) {
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
this.currentIndex = currentIndex;
|
||||
}
|
||||
|
||||
public int getText(char[] fillIn, int offset){
|
||||
int length = replaceable.length();
|
||||
if(offset < 0 || offset + length > fillIn.length){
|
||||
throw new IndexOutOfBoundsException(Integer.toString(length));
|
||||
}
|
||||
@ -206,8 +204,5 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
|
||||
* Current currentIndex
|
||||
*/
|
||||
private int currentIndex;
|
||||
/**
|
||||
* Replaceable text length
|
||||
*/
|
||||
private int length;
|
||||
|
||||
}
|
||||
|
@ -24,16 +24,10 @@ 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
|
||||
@ -42,7 +36,8 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @see #getBeginIndex()
|
||||
*/
|
||||
public char first(){
|
||||
iterator.setIndex(beginIndex);
|
||||
//UCharacterIterator always iterates from 0 to length
|
||||
iterator.setToStart();
|
||||
return (char)iterator.current();
|
||||
}
|
||||
|
||||
@ -53,8 +48,8 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @see #getEndIndex()
|
||||
*/
|
||||
public char last(){
|
||||
iterator.setIndex(length-1);
|
||||
return (char)iterator.current();
|
||||
iterator.setToLimit();
|
||||
return (char)iterator.previous();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,7 +59,6 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @see #getIndex()
|
||||
*/
|
||||
public char current(){
|
||||
iterator.setIndex(currentIndex);
|
||||
return (char) iterator.current();
|
||||
}
|
||||
|
||||
@ -78,7 +72,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
*/
|
||||
public char next(){
|
||||
//pre-increment
|
||||
iterator.setIndex(++currentIndex);
|
||||
iterator.next();
|
||||
return (char) iterator.current();
|
||||
}
|
||||
|
||||
@ -91,8 +85,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
*/
|
||||
public char previous(){
|
||||
//pre-decrement
|
||||
iterator.setIndex(--currentIndex);
|
||||
return (char) iterator.current();
|
||||
return (char) iterator.previous();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -104,7 +97,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
|
||||
*/
|
||||
public char setIndex(int position){
|
||||
currentIndex=position;
|
||||
iterator.setIndex(position);
|
||||
return (char) iterator.current();
|
||||
}
|
||||
|
||||
@ -113,7 +106,8 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the index at which the text begins.
|
||||
*/
|
||||
public int getBeginIndex(){
|
||||
return beginIndex;
|
||||
//UCharacterIterator always starts from 0
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -122,7 +116,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the index after the last character in the text
|
||||
*/
|
||||
public int getEndIndex(){
|
||||
return length;
|
||||
return iterator.getLength();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,7 +124,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
|
||||
* @return the current index.
|
||||
*/
|
||||
public int getIndex(){
|
||||
return currentIndex;
|
||||
return iterator.getIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user