ICU-2010 impove coverage

X-SVN-Rev: 9459
This commit is contained in:
Ram Viswanadha 2002-07-31 03:04:28 +00:00
parent 8606aeb57c
commit 4c56adc195
5 changed files with 53 additions and 76 deletions

View File

@ -24,39 +24,32 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
private CharacterIterator iterator;
/**
* Current index
*/
private int currentIndex;
/**
* length
*/
private int length;
/**
* cache of begin offset in character iterator
*/
private int beginIndex;
public CharacterIteratorWrapper(CharacterIterator iter){
if(iter==null){
throw new IllegalArgumentException();
}
iterator = iter;
currentIndex = 0;
beginIndex = iter.getBeginIndex();
length = iter.getEndIndex() - beginIndex;
length = iter.getEndIndex() - iter.getBeginIndex();
}
/**
* @see UCharacterIterator#current()
*/
public int current() {
if (currentIndex < length) {
/* if (currentIndex < length) {
return iterator.setIndex(beginIndex + currentIndex);
}
return DONE;
*/
int c = iterator.current();
if(c==iterator.DONE){
return DONE;
}
return c;
}
/**
@ -70,50 +63,71 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
* @see UCharacterIterator#getIndex()
*/
public int getIndex() {
return currentIndex;
//return currentIndex;
return iterator.getIndex();
}
/**
* @see UCharacterIterator#next()
*/
public int next() {
if(currentIndex < length){
/*if(currentIndex < length){
return iterator.setIndex(beginIndex + currentIndex++);
}
return DONE;
return DONE;
*/
int i = iterator.current();
iterator.next();
if(i==iterator.DONE){
return DONE;
}
return i;
}
/**
* @see UCharacterIterator#previous()
*/
public int previous() {
if(currentIndex>0){
/*if(currentIndex>0){
return iterator.setIndex(beginIndex + --currentIndex);
}
return DONE;
return DONE;
*/
int i = iterator.previous();
if(i==iterator.DONE){
return DONE;
}
return i;
}
/**
* @see UCharacterIterator#setIndex(int)
*/
public void setIndex(int index) {
if (index < 0 || index > length) {
/*if (index < 0 || index > length) {
throw new IndexOutOfBoundsException();
}
currentIndex = index;
*/
try{
iterator.setIndex(index);
}catch(IllegalArgumentException e){
throw new IndexOutOfBoundsException();
}
}
/**
* @see UCharacterIterator#setToLimit()
*/
public void setToLimit() {
currentIndex = length;
iterator.setIndex(length);
}
/**
* @see UCharacterIterator#getText(char[])
*/
public int getText(char[] fillIn, int offset){
int currentIndex = iterator.getIndex();
if(offset < 0 || offset + length > fillIn.length){
throw new IndexOutOfBoundsException(Integer.toString(length));
}
@ -121,7 +135,7 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
for (char ch = iterator.first(); ch != iterator.DONE; ch = iterator.next()) {
fillIn[offset++] = ch;
}
iterator.setIndex(beginIndex + currentIndex);
iterator.setIndex(currentIndex);
return length;
}
@ -144,14 +158,14 @@ public class CharacterIteratorWrapper extends UCharacterIterator {
* @see UCharacterIterator#moveIndex()
*/
public int moveIndex(int index){
currentIndex += index;
int idx = iterator.getIndex()+index;
if(currentIndex < 0) {
currentIndex = 0;
} else if(currentIndex > length) {
currentIndex = length;
if(idx < 0) {
idx = 0;
} else if(idx > length) {
idx = length;
}
return currentIndex;
return iterator.setIndex(idx);
}
/**

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/ReplaceableUCharacterIterator.java,v $
* $Date: 2002/07/19 22:08:46 $
* $Revision: 1.2 $
* $Date: 2002/07/31 03:04:28 $
* $Revision: 1.3 $
*
*******************************************************************************
*/
@ -56,19 +56,6 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
this.length = replaceable.length();
}
/**
* Public constructor
* @param src an array of characters on which the iterator will be based
*/
public ReplaceableUCharacterIterator(char[] src){
if(src==null){
throw new IllegalArgumentException();
}
this.replaceable = new ReplaceableString(new String(src));
this.currentIndex = 0;
this.length = replaceable.length();
}
/**
* Public constructor
* @param buf buffer of text on which the iterator will be based
@ -137,14 +124,6 @@ public class ReplaceableUCharacterIterator extends UCharacterIterator {
return ch;
}
/**
* Returns the start of the text.
* @return 0
*/
public int getBeginIndex(){
return 0;
}
/**
* Returns the length of the text
* @return length of the text

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/UCharArrayIterator.java,v $
* $Date: 2002/06/20 01:18:09 $
* $Revision: 1.1 $
* $Date: 2002/07/31 03:04:28 $
* $Revision: 1.2 $
*
*******************************************************************************
*/
@ -73,9 +73,6 @@ public final class UCharArrayIterator extends UCharacterIterator {
return len;
}
public String getString() {
return new String(text, start, limit - start);
}
/**
* Creates a copy of this iterator, does not clone the underlying
* <code>Replaceable</code>object

View File

@ -5,8 +5,8 @@
*******************************************************************************
*
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/Attic/UCharacterIterator.java,v $
* $Date: 2002/07/19 22:08:45 $
* $Revision: 1.10 $
* $Date: 2002/07/31 03:04:28 $
* $Revision: 1.11 $
*
*******************************************************************************
*/
@ -303,20 +303,7 @@ public abstract class UCharacterIterator
* @exception IndexOutOfBounds exception if there is not enough
* room after offset in the array, or if offset < 0.
*/
public int getText(char[] fillIn, int offset) {
int len = getLength();
if (offset < 0 || offset + len > fillIn.length) {
throw new IndexOutOfBoundsException(Integer.toString(offset));
}
int index = getIndex();
setToStart();
int ch;
while ((ch = next())!= DONE) {
fillIn[offset++] = (char)ch;
}
setIndex(index);
return len;
}
public abstract int getText(char[] fillIn, int offset);
/**
* Convenience override for <code>getText(char[], int)>/code> that provides

View File

@ -42,7 +42,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
* @see #getBeginIndex()
*/
public char first(){
iterator.setToStart();
iterator.setIndex(beginIndex);
return (char)iterator.current();
}
@ -53,7 +53,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
* @see #getEndIndex()
*/
public char last(){
iterator.setToLimit();
iterator.setIndex(length-1);
return (char)iterator.current();
}
@ -122,7 +122,7 @@ public class UCharacterIteratorWrapper implements CharacterIterator{
* @return the index after the last character in the text
*/
public int getEndIndex(){
return length-1;
return length;
}
/**