NpsSDK.ComplexElementArray Maven / Gradle / Ivy
package NpsSDK;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ComplexElementArray extends BaseElement {
private String _childType;
void setChildType(String childType){ this._childType = childType; }
public ComplexElementArray() {
this._children = new ArrayList();
this._typedChildren = new ArrayList();
}
private List _children;
@Override
List getChildren() {
return _children;
}
private List _typedChildren;
List getTypedChildren(){
return _typedChildren;
}
@Override
public String serialize() {
String serial = "";
for (BaseElement child : this.getChildren()) {
serial += String.format("- %2$s
", this._childType,child.serialize());
}
return String.format("<%1$s q2:arrayType=\"q3:%2$s[%3$s]\">%4$s%1$s>", this.getName(), this._childType, this._children.size(), serial);
}
@Override
String getConcatenatedValues() {
List elements = new ArrayList(this.getChildren());
Collections.sort(elements, new Comparator() {
@Override
public int compare(final BaseElement element1, final BaseElement element2) {
return element1.getName().compareTo(element2.getName());
}
});
List concatenatedValuesList = new ArrayList();
for (BaseElement element : elements) {
concatenatedValuesList.add(element.getConcatenatedValues());
}
return joinList("", concatenatedValuesList);
}
private String joinList(String delimiter, List stringList){
StringBuilder result = new StringBuilder();
for(int i = 0; i