getRunStart和getRunLimit的使用,难道就没有人知道吗?

lvzhe_cx 2004-07-19 09:42:46
刚试看了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();
}
}
}
}
...全文
82 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
ecaol 2004-07-19
  • 打赏
  • 举报
回复
UP

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧