com.github.davidmoten.oas3.internal.model.Model Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-to-plantuml Show documentation
Show all versions of openapi-to-plantuml Show documentation
Generates PlantUML file from an OpenAPI 3.0 Definition
package com.github.davidmoten.oas3.internal.model;
import static java.util.stream.Collectors.joining;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.github.davidmoten.guavamini.Lists;
public final class Model {
public static final Model EMPTY = new Model(Collections.emptyList(), Collections.emptyList());
private final List classes;
private final List relationships;
public Model(List classes, List relationships) {
this.classes = classes;
this.relationships = relationships;
}
public Model(Class cls, Relationship r) {
this(Collections.singletonList(cls), Collections.singletonList(r));
}
public Model(Class cls) {
this(Collections.singletonList(cls), Collections.emptyList());
}
public Model(Relationship r) {
this(Collections.emptyList(), Collections.singletonList(r));
}
public Model add(Model model) {
List c = Lists.newArrayList(classes);
List r = Lists.newArrayList(relationships);
c.addAll(model.classes);
r.addAll(model.relationships);
return new Model(c, r);
}
public Model add(Relationship r) {
List list = new ArrayList<>(relationships);
list.add(r);
return new Model(classes, list);
}
public List classes() {
return classes;
}
public List relationships() {
return relationships;
}
@Override
public String toString() {
StringBuilder b = new StringBuilder();
b.append("Model [");
b.append(classes.stream().map(x -> "\n " + x).collect(joining(",")));
b.append(relationships.stream().map(x -> "\n " + x).collect(joining(",")));
b.append("\n]");
return b.toString();
}
}