All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.davidmoten.oas3.internal.model.Model Maven / Gradle / Ivy

There is a newer version: 0.1.30
Show newest version
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();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy