java - How do you get AttributedCharacterIterator to return a run for a given Attribute? -
suppose assign custom characteriterator.attribute
first 5 characters of ten-character string.
suppose further assign different characteriterator.attribute
remaining characters.
why then, when call attributedstring.getrunstart(firstattribute)
0 (i expect this) , when call attributedstring.getrunstart(secondattribute)
also 0?
here's setup code:
final attributedstring s = new attributedstring("sq3r9fffff"); final attribute baseid = new attribute("base id") {}; final attribute fs = new attribute("fff") {}; s.addattribute(baseid, "ignored", 0, 5); s.addattribute(fs, "whatever", 5, 10); final attributedcharacteriterator iterator = s.getiterator(); assertnotnull(iterator);
and here's code outputs diagnostics:
for (char c = iterator.first(); c != done; c = iterator.next()) { system.out.println("character: " + c); system.out.println("character index: " + iterator.getindex()); system.out.println("attributes: " + iterator.getattributes()); system.out.println("start baseid: " + iterator.getrunstart(baseid)); system.out.println("limit baseid: " + iterator.getrunlimit(baseid)); system.out.println("start fs: " + iterator.getrunstart(fs)); system.out.println("limit fs: " + iterator.getrunlimit(fs)); }
the output this:
character: s character index: 0 attributes: {com.foobar.collection.api.testcaseattributedstring$1(base id)=ignored} start baseid: 0 limit baseid: 5 start fs: 0 limit fs: 5 character: q character index: 1 attributes: {com.foobar.collection.api.testcaseattributedstring$1(base id)=ignored} start baseid: 0 limit baseid: 5 start fs: 0 limit fs: 5 character: 3 character index: 2 attributes: {com.foobar.collection.api.testcaseattributedstring$1(base id)=ignored} start baseid: 0 limit baseid: 5 start fs: 0 limit fs: 5 character: r character index: 3 attributes: {com.foobar.collection.api.testcaseattributedstring$1(base id)=ignored} start baseid: 0 limit baseid: 5 start fs: 0 limit fs: 5 character: 9 character index: 4 attributes: {com.foobar.collection.api.testcaseattributedstring$1(base id)=ignored} start baseid: 0 limit baseid: 5 start fs: 0 limit fs: 5 character: f character index: 5 attributes: {com.foobar.collection.api.testcaseattributedstring$2(fff)=whatever} start baseid: 5 limit baseid: 10 start fs: 5 limit fs: 10 character: f character index: 6 attributes: {com.foobar.collection.api.testcaseattributedstring$2(fff)=whatever} start baseid: 5 limit baseid: 10 start fs: 5 limit fs: 10 character: f character index: 7 attributes: {com.foobar.collection.api.testcaseattributedstring$2(fff)=whatever} start baseid: 5 limit baseid: 10 start fs: 5 limit fs: 10 character: f character index: 8 attributes: {com.foobar.collection.api.testcaseattributedstring$2(fff)=whatever} start baseid: 5 limit baseid: 10 start fs: 5 limit fs: 10 character: f character index: 9 attributes: {com.foobar.collection.api.testcaseattributedstring$2(fff)=whatever} start baseid: 5 limit baseid: 10 start fs: 5 limit fs: 10
note, in particular, last entry, reports "start" "baseid" 5. huh?
per javadoc:
a run respect attribute maximum text range which:
- the attribute undefined or null entire range, or
- the attribute value defined , has same non-null value entire range.
i think may first bullet point. characters 0-4, fs attribute undefined, it's valid range. baseid defined, , valid.
http://download.oracle.com/javase/1,5.0/docs/api/java/text/attributedcharacteriterator.html
Comments
Post a Comment