// 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) {
@SuppressWarnings("unchecked")
final List<Object> list = (List<Object>) value;
v = new AttributeList(list.size());
// flatten incoming list into existing
v.addAll(list);
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
@SuppressWarnings("unchecked")
List<Object> listAttr = (List<Object>) 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
@SuppressWarnings("unchecked")
final List<Object> list = (List<Object>) value;
v.addAll(list);
}
} else {
v.add(value);
}
}