{
// Validate some arguments
if ((begin < 0) || (end < begin) || end > aci.getEndIndex())
throw new IllegalArgumentException("Bad index values");
CPStringBuilder sb = new CPStringBuilder("");
// Get the valid attribute list
Set allAttribs = aci.getAllAttributeKeys();
if (attributes != null)
allAttribs.retainAll(Arrays.asList(attributes));
// Loop through and extract the attributes
char c = aci.setIndex(begin);
ArrayList accum = new ArrayList();
do
{
sb.append(c);
Iterator iter = allAttribs.iterator();
while(iter.hasNext())
{
Object obj = iter.next();
// What should we do if this is not true?
if (!(obj instanceof AttributedCharacterIterator.Attribute))
continue;
AttributedCharacterIterator.Attribute attrib =
(AttributedCharacterIterator.Attribute)obj;
// Make sure the attribute is defined.
Object attribObj = aci.getAttribute(attrib);
if (attribObj == null)
continue;
int rl = aci.getRunLimit(attrib);
if (rl > end)
rl = end;
rl -= begin;
// Check to see if we already processed this one
int rs = aci.getRunStart(attrib);
if ((rs < aci.getIndex()) && (aci.getIndex() != begin))
continue;
// If the attribute run starts before the beginning index, we
// need to junk it if it is an Annotation.
rs -= begin;
if (rs < 0)
{
if (attribObj instanceof Annotation)
continue;
rs = 0;
}
// Create a map object. Yes this will only contain one attribute
Map newMap = new Hashtable();
newMap.put(attrib, attribObj);
// Add it to the attribute list.
accum.add(new AttributeRange(newMap, rs, rl));
}
c = aci.next();
}
while( aci.getIndex() < end );
attribs = new AttributeRange[accum.size()];
attribs = (AttributeRange[]) accum.toArray(attribs);
sci = new StringCharacterIterator(sb.toString());
}