刚试看了java.text,对其中AttributedCharacterIterator的使用不理解。
尤其是下面这段话:
A run with respect to an attribute is a maximum text range for which:   the attribute is undefined or null for the entire range, or 
  the attribute value is defined and has the same non-null value for the entire range. A run with respect to a set of attributes is a maximum text range for which this condition is met for each member attribute. 这个'Run'的范围究竟是如何确定的呢?我试着写了段代码,看看它到底会输出怎样的结果,但还是不理解,有人能提供一些解释吗?例如,当前字符为'8',attribute的key为'integer'时,为什么getRunStart和getRunLimit的结果分别为9和12。
谢谢!import java.text.*;
import java.util.*;
public class TextTest { public static void main(String[] args) { double aDouble=1234567.89; DecimalFormat dFormat=new DecimalFormat();
String aStr=dFormat.format(aDouble);
System.out.println("aStr= "+ aStr);
AttributedCharacterIterator attCharIterator= dFormat.formatToCharacterIterator(new Double(aDouble));
System.out.println("begin idx is "+ attCharIterator.getBeginIndex());
System.out.println("end idx is "+ attCharIterator.getEndIndex());
HashSet attrKeys=new HashSet(attCharIterator.getAllAttributeKeys());
System.out.println("attribute keys are "+ attrKeys);
for(char c = attCharIterator.first(); c != CharacterIterator.DONE; c = attCharIterator.next()) {
System.out.println("current char is "+ c);
System.out.println("\tcurrent runstart for all attr is "+attCharIterator.getRunStart());
System.out.println("\tcurrent runlimit for all attr is "+attCharIterator.getRunLimit());
System.out.println();
for(Iterator i= attrKeys.iterator();i.hasNext();) {
AttributedCharacterIterator.Attribute curAtttrKey=(AttributedCharacterIterator.Attribute)i.next();
System.out.println("\tcurrent key is "+ curAtttrKey);
System.out.println("\tcurrent val is "+attCharIterator.getAttribute(curAtttrKey)); System.out.println("\tcurrent runstart is "+attCharIterator.getRunStart(curAtttrKey));
System.out.println("\tcurrent runlimit is "+attCharIterator.getRunLimit(curAtttrKey));

System.out.println();
}
}
}
}