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

org.anarres.graphviz.builder.GraphVizEdge 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 com.google.common.base.Preconditions;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

/**
 *
 * @author shevek
 */
public class GraphVizEdge extends GraphVizElement {

    /* pp */ static final class Key {

        @Nonnull
        private final GraphVizObject.Key sourceKey;
        @Nonnull
        private final GraphVizObject.Key targetKey;
        @CheckForNull
        private final Object edgeId;

        public Key(@Nonnull GraphVizObject.Key sourceKey, @Nonnull GraphVizObject.Key targetKey, @CheckForNull Object edgeId) {
            this.sourceKey = Preconditions.checkNotNull(sourceKey, "Source key was null.");
            this.targetKey = Preconditions.checkNotNull(targetKey, "Target key was null.");
            this.edgeId = edgeId;
        }

        @Nonnull
        public GraphVizObject.Key getSourceKey() {
            return sourceKey;
        }

        @Nonnull
        public GraphVizObject.Key getTargetKey() {
            return targetKey;
        }

        @CheckForNull
        public Object getEdgeId() {
            return edgeId;
        }

        @Override
        public int hashCode() {
            return getSourceKey().hashCode() ^ getTargetKey().hashCode() ^ GraphVizUtils.hashCode(getEdgeId());
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            Key k = (Key) obj;
            return getSourceKey().equals(k.getSourceKey())
                    && getTargetKey().equals(k.getTargetKey())
                    && GraphVizUtils.equals(getEdgeId(), k.getEdgeId());
        }
    }
    @Nonnull
    private final Key key;
    @Nonnull
    private final String sourceId;
    @Nonnull
    private final String targetId;
    @CheckForNull
    private String headShape;
    @CheckForNull
    private String headLabel;
    @CheckForNull
    private String tailShape;
    @CheckForNull
    private String tailLabel;
    @CheckForNull
    private String logicalHead;
    @CheckForNull
    private String logicalTail;

    /* pp */ GraphVizEdge(@Nonnull GraphVizGraph graph, @Nonnull Key key, @Nonnull String sourceId, @Nonnull String targetId) {
        super(graph);
        this.key = key;
        this.sourceId = sourceId;
        this.targetId = targetId;
    }

    @Nonnull
    /* pp */ Key getKey() {
        return key;
    }

    @Nonnull
    /* pp */ String getSourceId() {
        return sourceId;
    }

    @Nonnull
    /* pp */ String getTargetId() {
        return targetId;
    }

    @CheckForNull
    public String getHeadShape() {
        return headShape;
    }

    @Nonnull
    public GraphVizEdge headShape(@CheckForNull String headShape) {
        this.headShape = headShape;
        return this;
    }

    @CheckForNull
    public String getHeadLabel() {
        return headLabel;
    }

    @Nonnull
    public GraphVizEdge headLabel(@CheckForNull String headLabel) {
        this.headLabel = headLabel;
        return this;
    }

    @CheckForNull
    public String getTailShape() {
        return tailShape;
    }

    @Nonnull
    public GraphVizEdge tailShape(@CheckForNull String tailShape) {
        this.tailShape = tailShape;
        return this;
    }

    @CheckForNull
    public String getTailLabel() {
        return tailLabel;
    }

    @Nonnull
    public GraphVizEdge tailLabel(@CheckForNull String tailLabel) {
        this.tailLabel = tailLabel;
        return this;
    }

    public String getLogicalHead() {
        return logicalHead;
    }

    @Nonnull
    public GraphVizEdge logicalHead(@CheckForNull String logicalHead) {
        this.logicalHead = logicalHead;
        return this;
    }

    public String getLogicalTail() {
        return logicalTail;
    }

    @Nonnull
    public GraphVizEdge logicalTail(@CheckForNull String logicalTail) {
        this.logicalTail = logicalTail;
        return this;
    }

    @Nonnull
    public GraphVizEdge constraint(boolean value) {
        return attr(GraphVizAttribute.constraint, Boolean.toString(value));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy