// convert plain collections
// get exactly in this scope (no enclosing)
// it will be a multi-value attribute
// System.out.println("exists: "+name+"="+o);
AttributeList v = null;
Object o = this.attributes.get(name);
if (o == null) { // new attribute
if (value instanceof List) {
v = new AttributeList(((List) value).size());
// flatten incoming list into existing
v.addAll((List) value);
rawSetAttribute(this.attributes, name, v);
return;
}
rawSetAttribute(this.attributes, name, value);
return;
}
if (o.getClass() == AttributeList.class) { // already a list made by ST
v = (AttributeList) o;
} else if (o instanceof List) { // existing attribute is non-ST List
// must copy to an ST-managed list before adding new attribute
List listAttr = (List) o;
v = new AttributeList(listAttr.size());
v.addAll(listAttr);
rawSetAttribute(this.attributes, name, v); // replace attribute w/list
} else {
// non-list second attribute, must convert existing to ArrayList
v = new AttributeList(); // make list to hold multiple values
// make it point to list now
rawSetAttribute(this.attributes, name, v); // replace attribute w/list
v.add(o); // add previous single-valued attribute
}
if (value instanceof List) {
// flatten incoming list into existing
if (v != value) { // avoid weird cyclic add
v.addAll((List) value);
}
} else {
v.add(value);
}
}