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

org.anarres.graphviz.builder.GraphVizCluster Maven / Gradle / Ivy

There is a newer version: 1.0.12
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.anarres.graphviz.builder;

import java.util.HashSet;
import java.util.Set;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
 *
 * @author shevek
 */
public class GraphVizCluster extends GraphVizObject {

    @CheckForNull
    private final GraphVizCluster parent;
    @Nonnull
    private final Set clusterKeys = new HashSet();
    @Nonnull
    private final Set nodeKeys = new HashSet();

    /* pp */ GraphVizCluster(@Nonnull GraphVizGraph graph, @Nonnull Key key, @CheckForNull GraphVizCluster parent, int id) {
        super(graph, key, (parent == null ? "cluster_c" : parent.getId() + "_") + id);
        this.parent = parent;
    }

    @CheckForNull
    public GraphVizCluster getParent() {
        return parent;
    }

    @Nonnull
    /* pp */ Set getClusterKeys() {
        return clusterKeys;
    }

    @Nonnull
    /* pp */ Set getNodeKeys() {
        return nodeKeys;
    }

    // Force this to take at least one object so people don't miss the scope argument.
    @Nonnull
    public GraphVizCluster add(@Nonnull GraphVizNode... nodes) {
        for (GraphVizNode node : nodes)
            nodeKeys.add(node.getKey());
        return this;
    }

    @Nonnull
    public GraphVizCluster add(@Nonnull GraphVizScope scope, @Nonnull Object... objects) {
        for (Object object : objects)
            nodeKeys.add(new GraphVizObject.Key(scope, object));
        return this;
    }

    @Nonnull
    public GraphVizCluster add(@Nonnull GraphVizScope scope, @Nonnull Iterable objects) {
        for (Object object : objects)
            nodeKeys.add(new GraphVizObject.Key(scope, object));
        return this;
    }
}