ICU-1611
Changes made from discussion feedback. Results to be stored in passed parameter element. X-SVN-Rev: 7612
This commit is contained in:
parent
21222853da
commit
6e0a407fda
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/dev/test/lang/UCharacterTest.java,v $
|
||||
* $Date: 2002/02/08 01:08:38 $
|
||||
* $Revision: 1.20 $
|
||||
* $Date: 2002/02/08 23:44:17 $
|
||||
* $Revision: 1.21 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -929,38 +929,38 @@ public final class UCharacterTest extends TestFmwk
|
||||
*/
|
||||
public void TestIteration()
|
||||
{
|
||||
int end = 0;
|
||||
int limit = 0;
|
||||
int prevtype = -1;
|
||||
RangeValueIterator iterator = UCharacter.getTypeIterator();
|
||||
while (iterator.next()) {
|
||||
int start = iterator.getStart();
|
||||
if (start != end) {
|
||||
RangeValueIterator.Element result = new RangeValueIterator.Element();
|
||||
while (iterator.next(result)) {
|
||||
if (result.start != limit) {
|
||||
errln("UCharacterEnumeration failed: Ranges not continuous " +
|
||||
"0x" + Integer.toHexString(start));
|
||||
"0x" + Integer.toHexString(result.start));
|
||||
}
|
||||
|
||||
end = iterator.getLimit();
|
||||
int type = iterator.getValue();
|
||||
|
||||
if (type == prevtype) {
|
||||
limit = result.limit;
|
||||
if (result.value == prevtype) {
|
||||
errln("Type of the next set of enumeration should be different");
|
||||
}
|
||||
prevtype = result.value;
|
||||
/*
|
||||
System.out.println("start and end " + Integer.toHexString(start) +
|
||||
" " + Integer.toHexString(end));
|
||||
*/
|
||||
for (int i = start; i < end; i ++) {
|
||||
for (int i = result.start; i < limit; i ++) {
|
||||
int temptype = UCharacter.getType(i);
|
||||
if (temptype != type) {
|
||||
if (temptype != result.value) {
|
||||
errln("UCharacterEnumeration failed: Codepoint \\u" +
|
||||
Integer.toHexString(i) + " should be of type " +
|
||||
UCharacter.getType(i) + " not " + type);
|
||||
UCharacter.getType(i) + " not " + result.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator.reset();
|
||||
if (iterator.next() == false || iterator.getStart() != 0) {
|
||||
if (iterator.next(result) == false || result.start != 0) {
|
||||
System.out.println("result " + result.start);
|
||||
errln("UCharacterEnumeration reset() failed");
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,8 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/impl/TrieIterator.java,v $
|
||||
* $Date: 2002/02/08 01:12:44 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:44:22 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@ -63,9 +63,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
* <p>Returns true if we are not at the end of the iteration, false
|
||||
* otherwise.</p>
|
||||
* <p>The next set of codepoints with the same value type will be
|
||||
* calculated during this call. To retrieve the set of codepoints and
|
||||
* their common value, the methods getStart(), getLimit() and getValue()
|
||||
* can be called.</p>
|
||||
* calculated during this call and returned in the arguement element.</p>
|
||||
* @param element return result
|
||||
* @return true if we are not at the end of the iteration, false otherwise.
|
||||
* @exception NoSuchElementException - if no more elements exist.
|
||||
* @see #getStart()
|
||||
@ -73,55 +72,19 @@ public class TrieIterator implements RangeValueIterator
|
||||
* @see #getValue()
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final boolean next()
|
||||
public final boolean next(Element element)
|
||||
{
|
||||
if (m_nextCodepoint_ > UCharacter.MAX_VALUE) {
|
||||
return false;
|
||||
}
|
||||
if (m_nextCodepoint_ < UCharacter.SUPPLEMENTARY_MIN_VALUE &&
|
||||
calculateNextBMPElement()) {
|
||||
calculateNextBMPElement(element)) {
|
||||
return true;
|
||||
}
|
||||
calculateNextSupplementaryElement();
|
||||
calculateNextSupplementaryElement(element);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the start codepoint of the result range with the same value, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return start codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getStart()
|
||||
{
|
||||
return m_start_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the (end + 1) codepoint of result range with the same value, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return (end + 1) codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getLimit()
|
||||
{
|
||||
return m_limit_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the common value of the codepoints in the result range, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return common value of the codepoints in the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getValue()
|
||||
{
|
||||
return m_value_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the iterator to the beginning of the iteration
|
||||
* @draft 2.1
|
||||
@ -140,7 +103,6 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
m_nextBlockIndex_ = 0;
|
||||
m_nextTrailIndexOffset_ = TRAIL_SURROGATE_INDEX_BLOCK_LENGTH_;
|
||||
setResult(0, 0, m_nextValue_);
|
||||
}
|
||||
|
||||
// protected methods ----------------------------------------------
|
||||
@ -164,15 +126,17 @@ public class TrieIterator implements RangeValueIterator
|
||||
|
||||
/**
|
||||
* Set the result values
|
||||
* @param element return result object
|
||||
* @param start codepoint of range
|
||||
* @param limit (end + 1) codepoint of range
|
||||
* @param value common value of range
|
||||
*/
|
||||
private final void setResult(int start, int limit, int value)
|
||||
private final void setResult(Element element, int start, int limit,
|
||||
int value)
|
||||
{
|
||||
m_start_ = start;
|
||||
m_limit_ = limit;
|
||||
m_value_ = value;
|
||||
element.start = start;
|
||||
element.limit = limit;
|
||||
element.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,10 +146,11 @@ public class TrieIterator implements RangeValueIterator
|
||||
* We always store the next element before it is requested.
|
||||
* In the case that we have to continue calculations into the
|
||||
* supplementary planes, a false will be returned.
|
||||
* @param element return result object
|
||||
* @return true if the next range is found, false if we have to proceed to
|
||||
* the supplementary range.
|
||||
*/
|
||||
private final boolean calculateNextBMPElement()
|
||||
private final boolean calculateNextBMPElement(Element element)
|
||||
{
|
||||
int currentBlock = m_nextBlock_;
|
||||
int currentValue = m_nextValue_;
|
||||
@ -193,7 +158,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextCodepoint_ ++;
|
||||
m_nextBlockIndex_ ++;
|
||||
if (!checkBlockDetail(currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
// enumerate BMP - the main loop enumerates data blocks
|
||||
@ -214,7 +180,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
|
||||
m_nextBlockIndex_ = 0;
|
||||
if (!checkBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
@ -239,9 +205,10 @@ public class TrieIterator implements RangeValueIterator
|
||||
* the end before resetting it to the new value.
|
||||
* Note, if there are no more iterations, it will never get to here.
|
||||
* Blocked out by next().
|
||||
* @param element return result object
|
||||
* @draft 2.1
|
||||
*/
|
||||
private final void calculateNextSupplementaryElement()
|
||||
private final void calculateNextSupplementaryElement(Element element)
|
||||
{
|
||||
int currentValue = m_nextValue_;
|
||||
int currentBlock = m_nextBlock_;
|
||||
@ -249,7 +216,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextBlockIndex_ ++;
|
||||
|
||||
if (!checkNullNextTrailIndex() && !checkBlockDetail(currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
}
|
||||
@ -257,7 +225,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextIndex_ ++;
|
||||
m_nextTrailIndexOffset_ ++;
|
||||
if (!checkTrailBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
}
|
||||
@ -291,7 +260,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextValue_ = m_initialValue_;
|
||||
m_nextBlock_ = 0;
|
||||
m_nextBlockIndex_ = 0;
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -300,7 +269,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
} else {
|
||||
m_nextTrailIndexOffset_ = 0;
|
||||
if (!checkTrailBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -310,7 +279,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
|
||||
// deliver last range
|
||||
setResult(m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
setResult(element, m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
currentValue);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/internal/util/Attic/TrieIterator.java,v $
|
||||
* $Date: 2002/02/08 01:12:44 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:44:22 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
@ -63,9 +63,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
* <p>Returns true if we are not at the end of the iteration, false
|
||||
* otherwise.</p>
|
||||
* <p>The next set of codepoints with the same value type will be
|
||||
* calculated during this call. To retrieve the set of codepoints and
|
||||
* their common value, the methods getStart(), getLimit() and getValue()
|
||||
* can be called.</p>
|
||||
* calculated during this call and returned in the arguement element.</p>
|
||||
* @param element return result
|
||||
* @return true if we are not at the end of the iteration, false otherwise.
|
||||
* @exception NoSuchElementException - if no more elements exist.
|
||||
* @see #getStart()
|
||||
@ -73,55 +72,19 @@ public class TrieIterator implements RangeValueIterator
|
||||
* @see #getValue()
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final boolean next()
|
||||
public final boolean next(Element element)
|
||||
{
|
||||
if (m_nextCodepoint_ > UCharacter.MAX_VALUE) {
|
||||
return false;
|
||||
}
|
||||
if (m_nextCodepoint_ < UCharacter.SUPPLEMENTARY_MIN_VALUE &&
|
||||
calculateNextBMPElement()) {
|
||||
calculateNextBMPElement(element)) {
|
||||
return true;
|
||||
}
|
||||
calculateNextSupplementaryElement();
|
||||
calculateNextSupplementaryElement(element);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the start codepoint of the result range with the same value, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return start codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getStart()
|
||||
{
|
||||
return m_start_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the (end + 1) codepoint of result range with the same value, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return (end + 1) codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getLimit()
|
||||
{
|
||||
return m_limit_;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the common value of the codepoints in the result range, after
|
||||
* the last call to next(). This method will not return a valid result if
|
||||
* next() was never called.
|
||||
* @return common value of the codepoints in the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public final int getValue()
|
||||
{
|
||||
return m_value_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resets the iterator to the beginning of the iteration
|
||||
* @draft 2.1
|
||||
@ -140,7 +103,6 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
m_nextBlockIndex_ = 0;
|
||||
m_nextTrailIndexOffset_ = TRAIL_SURROGATE_INDEX_BLOCK_LENGTH_;
|
||||
setResult(0, 0, m_nextValue_);
|
||||
}
|
||||
|
||||
// protected methods ----------------------------------------------
|
||||
@ -164,15 +126,17 @@ public class TrieIterator implements RangeValueIterator
|
||||
|
||||
/**
|
||||
* Set the result values
|
||||
* @param element return result object
|
||||
* @param start codepoint of range
|
||||
* @param limit (end + 1) codepoint of range
|
||||
* @param value common value of range
|
||||
*/
|
||||
private final void setResult(int start, int limit, int value)
|
||||
private final void setResult(Element element, int start, int limit,
|
||||
int value)
|
||||
{
|
||||
m_start_ = start;
|
||||
m_limit_ = limit;
|
||||
m_value_ = value;
|
||||
element.start = start;
|
||||
element.limit = limit;
|
||||
element.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -182,10 +146,11 @@ public class TrieIterator implements RangeValueIterator
|
||||
* We always store the next element before it is requested.
|
||||
* In the case that we have to continue calculations into the
|
||||
* supplementary planes, a false will be returned.
|
||||
* @param element return result object
|
||||
* @return true if the next range is found, false if we have to proceed to
|
||||
* the supplementary range.
|
||||
*/
|
||||
private final boolean calculateNextBMPElement()
|
||||
private final boolean calculateNextBMPElement(Element element)
|
||||
{
|
||||
int currentBlock = m_nextBlock_;
|
||||
int currentValue = m_nextValue_;
|
||||
@ -193,7 +158,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextCodepoint_ ++;
|
||||
m_nextBlockIndex_ ++;
|
||||
if (!checkBlockDetail(currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
// enumerate BMP - the main loop enumerates data blocks
|
||||
@ -214,7 +180,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
|
||||
m_nextBlockIndex_ = 0;
|
||||
if (!checkBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
return true;
|
||||
}
|
||||
@ -239,9 +205,10 @@ public class TrieIterator implements RangeValueIterator
|
||||
* the end before resetting it to the new value.
|
||||
* Note, if there are no more iterations, it will never get to here.
|
||||
* Blocked out by next().
|
||||
* @param element return result object
|
||||
* @draft 2.1
|
||||
*/
|
||||
private final void calculateNextSupplementaryElement()
|
||||
private final void calculateNextSupplementaryElement(Element element)
|
||||
{
|
||||
int currentValue = m_nextValue_;
|
||||
int currentBlock = m_nextBlock_;
|
||||
@ -249,7 +216,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextBlockIndex_ ++;
|
||||
|
||||
if (!checkNullNextTrailIndex() && !checkBlockDetail(currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
}
|
||||
@ -257,7 +225,8 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextIndex_ ++;
|
||||
m_nextTrailIndexOffset_ ++;
|
||||
if (!checkTrailBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_, currentValue);
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
}
|
||||
@ -291,7 +260,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
m_nextValue_ = m_initialValue_;
|
||||
m_nextBlock_ = 0;
|
||||
m_nextBlockIndex_ = 0;
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -300,7 +269,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
} else {
|
||||
m_nextTrailIndexOffset_ = 0;
|
||||
if (!checkTrailBlock(currentBlock, currentValue)) {
|
||||
setResult(m_currentCodepoint_, m_nextCodepoint_,
|
||||
setResult(element, m_currentCodepoint_, m_nextCodepoint_,
|
||||
currentValue);
|
||||
m_currentCodepoint_ = m_nextCodepoint_;
|
||||
return;
|
||||
@ -310,7 +279,7 @@ public class TrieIterator implements RangeValueIterator
|
||||
}
|
||||
|
||||
// deliver last range
|
||||
setResult(m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
setResult(element, m_currentCodepoint_, UCharacter.MAX_VALUE + 1,
|
||||
currentValue);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
*******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/test/text/Attic/UCharacterTest.java,v $
|
||||
* $Date: 2002/02/08 01:08:38 $
|
||||
* $Revision: 1.20 $
|
||||
* $Date: 2002/02/08 23:44:17 $
|
||||
* $Revision: 1.21 $
|
||||
*
|
||||
*******************************************************************************
|
||||
*/
|
||||
@ -929,38 +929,38 @@ public final class UCharacterTest extends TestFmwk
|
||||
*/
|
||||
public void TestIteration()
|
||||
{
|
||||
int end = 0;
|
||||
int limit = 0;
|
||||
int prevtype = -1;
|
||||
RangeValueIterator iterator = UCharacter.getTypeIterator();
|
||||
while (iterator.next()) {
|
||||
int start = iterator.getStart();
|
||||
if (start != end) {
|
||||
RangeValueIterator.Element result = new RangeValueIterator.Element();
|
||||
while (iterator.next(result)) {
|
||||
if (result.start != limit) {
|
||||
errln("UCharacterEnumeration failed: Ranges not continuous " +
|
||||
"0x" + Integer.toHexString(start));
|
||||
"0x" + Integer.toHexString(result.start));
|
||||
}
|
||||
|
||||
end = iterator.getLimit();
|
||||
int type = iterator.getValue();
|
||||
|
||||
if (type == prevtype) {
|
||||
limit = result.limit;
|
||||
if (result.value == prevtype) {
|
||||
errln("Type of the next set of enumeration should be different");
|
||||
}
|
||||
prevtype = result.value;
|
||||
/*
|
||||
System.out.println("start and end " + Integer.toHexString(start) +
|
||||
" " + Integer.toHexString(end));
|
||||
*/
|
||||
for (int i = start; i < end; i ++) {
|
||||
for (int i = result.start; i < limit; i ++) {
|
||||
int temptype = UCharacter.getType(i);
|
||||
if (temptype != type) {
|
||||
if (temptype != result.value) {
|
||||
errln("UCharacterEnumeration failed: Codepoint \\u" +
|
||||
Integer.toHexString(i) + " should be of type " +
|
||||
UCharacter.getType(i) + " not " + type);
|
||||
UCharacter.getType(i) + " not " + result.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
iterator.reset();
|
||||
if (iterator.next() == false || iterator.getStart() != 0) {
|
||||
if (iterator.next(result) == false || result.start != 0) {
|
||||
System.out.println("result " + result.start);
|
||||
errln("UCharacterEnumeration reset() failed");
|
||||
}
|
||||
}
|
||||
|
@ -5,17 +5,14 @@
|
||||
******************************************************************************
|
||||
*
|
||||
* $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/util/RangeValueIterator.java,v $
|
||||
* $Date: 2002/02/08 01:12:45 $
|
||||
* $Revision: 1.1 $
|
||||
* $Date: 2002/02/08 23:44:22 $
|
||||
* $Revision: 1.2 $
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
package com.ibm.icu.util;
|
||||
|
||||
import com.ibm.text.UCharacter;
|
||||
import com.ibm.text.UTF16;
|
||||
|
||||
/**
|
||||
* <p>Interface for enabling iteration over any set of integers, giving
|
||||
* back a maximum continuous range of integer result with a common value.
|
||||
@ -39,71 +36,64 @@ import com.ibm.text.UTF16;
|
||||
* Example of use:<br>
|
||||
* <pre>
|
||||
* RangeValueIterator iterator = UCharacter.getTypeIterator();
|
||||
* while (iterator.next()) {
|
||||
* RangeValueIterator.Element result = new RangeValueIterator.Element();
|
||||
* while (iterator.next(result)) {
|
||||
* System.out.println("Codepoint \\u" +
|
||||
* Integer.toHexString(iterator.getStart()) +
|
||||
* Integer.toHexString(result.start) +
|
||||
* " to codepoint \\u" +
|
||||
* Integer.toHexString(iterator.getLimit() - 1) +
|
||||
* " has the character type " +
|
||||
* iterator.getValue());
|
||||
* Integer.toHexString(result.limit - 1) +
|
||||
* " has the character type " + result.value);
|
||||
* }
|
||||
* </pre>
|
||||
* @author synwee
|
||||
* @since release 2.1, Jan 17 2002
|
||||
*/
|
||||
public interface RangeValueIterator
|
||||
|
||||
{
|
||||
// public inner class ---------------------------------------------
|
||||
|
||||
/**
|
||||
* Return result wrapper for com.ibm.icu.util.RangeValueIterator.
|
||||
* Stores the start and limit of the continous result range and the
|
||||
* common value all integers between [start, limit - 1] has.
|
||||
*/
|
||||
public class Element
|
||||
{
|
||||
/**
|
||||
* Starting integer of the continuous result range that has the same
|
||||
* value
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int start;
|
||||
/**
|
||||
* (End + 1) integer of continuous result range that has the same
|
||||
* value
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int limit;
|
||||
/**
|
||||
* Gets the common value of the continous result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int value;
|
||||
}
|
||||
|
||||
// public methods -------------------------------------------------
|
||||
|
||||
/**
|
||||
* <p>Returns true if we are not at the end of the iteration, false
|
||||
* otherwise.</p>
|
||||
* <p>The next set of integers with the same value will be
|
||||
* calculated during this call. To retrieve the set of integers and
|
||||
* their common value, the methods getStart(), getLimit() and getValue()
|
||||
* can be called.</p>
|
||||
* <p>Gets the next maximal result range with a common value and returns
|
||||
* true if we are not at the end of the iteration, false otherwise.</p>
|
||||
* <p>If the return boolean is a false, the contents of elements will not
|
||||
* be updated.</p>
|
||||
* @param element for storing the result range and value
|
||||
* @return true if we are not at the end of the iteration, false otherwise.
|
||||
* @see #getStart()
|
||||
* @see #getLimit()
|
||||
* @see #getValue()
|
||||
* @see Element
|
||||
* @draft 2.1
|
||||
*/
|
||||
public boolean next();
|
||||
public boolean next(Element element);
|
||||
|
||||
/**
|
||||
* Gets the starting integer of the result range with the same value, after
|
||||
* the last call to next(). This method will return Integer.MIN_VALUE
|
||||
* if next() has never been called or if reset() was the last call before
|
||||
* the getter methods.
|
||||
* @return start codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int getStart();
|
||||
|
||||
/**
|
||||
* Gets the (end + 1) integer of result range with the same value, after
|
||||
* the last call to next(). This method will return Integer.MIN_VALUE
|
||||
* if next() has never been called or if reset() was the last call before
|
||||
* the getter methods.
|
||||
* @return (end + 1) codepoint of the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int getLimit();
|
||||
|
||||
/**
|
||||
* Gets the common value of the result range, after
|
||||
* the last call to next(). This method will return Integer.MIN_VALUE
|
||||
* if next() has never been called or if reset() was the last call before
|
||||
* the getter methods.
|
||||
* @return common value of the codepoints in the result range
|
||||
* @draft 2.1
|
||||
*/
|
||||
public int getValue();
|
||||
|
||||
/**
|
||||
* Resets the iterator to the beginning of the iteration and initializes
|
||||
* start, limit and value to Integer.MIN_VALUE.
|
||||
* Resets the iterator to the beginning of the iteration.
|
||||
* @draft 2.1
|
||||
*/
|
||||
public void reset();
|
||||
|
Loading…
Reference in New Issue
Block a user