avoid array list creation

This commit is contained in:
Vladimir Krivosheev
2014-09-27 21:18:10 +02:00
parent 7a58252d60
commit 6d627c2b06
@@ -144,16 +144,24 @@ public class StorageData {
void setState(@NotNull final String componentName, final Element element) {
element.setName(COMPONENT);
//componentName should be first!
final List<Attribute> attributes = new ArrayList<Attribute>(element.getAttributes());
for (Attribute attribute : attributes) {
element.removeAttribute(attribute);
// componentName should be first
List<Attribute> elementAttributes = element.getAttributes();
if (elementAttributes.isEmpty()) {
element.setAttribute(NAME, componentName);
}
element.setAttribute(NAME, componentName);
for (Attribute attribute : attributes) {
element.setAttribute(attribute.getName(), attribute.getValue());
else {
Attribute nameAttribute = element.getAttribute(NAME);
if (nameAttribute == null) {
nameAttribute = new Attribute(NAME, componentName);
elementAttributes.add(0, nameAttribute);
}
else {
nameAttribute.setValue(componentName);
if (elementAttributes.get(0) != nameAttribute) {
elementAttributes.remove(nameAttribute);
elementAttributes.add(0, nameAttribute);
}
}
}
myComponentStates.put(componentName, element);