io.vertx.codetrans.expression.Member Maven / Gradle / Ivy
package io.vertx.codetrans.expression;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* @author Julien Viet
*/
public abstract class Member {
final String name;
public Member(String name) {
this.name = name;
}
public String getName() {
return name;
}
public static class Single extends Member {
ExpressionModel value;
public Single(String name) {
super(name);
}
public ExpressionModel getValue() {
return value;
}
protected Member append(ExpressionModel value) {
this.value = value;
return this;
}
}
public static class Sequence extends Member {
List values = new ArrayList<>();
public Sequence(String name) {
super(name);
}
public List getValues() {
return values;
}
protected Member append(ExpressionModel value) {
this.values.add(value);
return this;
}
protected Member append(List value) {
this.values.addAll(value);
return this;
}
}
public static class Entries extends Member {
Map> entries = new LinkedHashMap<>();
public Entries(String name) {
super(name);
}
protected Member append(String key, ExpressionModel value) {
entries.computeIfAbsent(key, k -> new ArrayList<>()).add(value);
return this;
}
public Iterable entries() {
List members = new ArrayList<>();
this.entries.forEach((k, v) -> {
if (v.size() == 1) {
members.add(new Single(k).append(v.get(0)));
} else {
members.add(new Sequence(k).append(v));
}
});
return members;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy