defaultedge.java

来自「JPowerGraph is a Java library for creati」· Java 代码 · 共 82 行

JAVA
82
字号
package net.sourceforge.jpowergraph;

/**
 * The default implementation of the edge.
 */
public class DefaultEdge implements Edge {
    /** The node from the edge. */
    protected Node m_from;
    /** The node to the edge. */
    protected Node m_to;

    /**
     * Creates an instance of this class.
     *
     * @param from                  the node from
     * @param to                    the node to
     */
    public DefaultEdge(Node from,Node to) {
        m_from=from;
        m_to=to;
    }
    /**
     * Returns the node from which this edge points.
     *
     * @return                       the node from which this edge points
     */
    public Node getFrom() {
        return m_from;
    }
    /**
     * Returns the node from which to edge points.
     *
     * @return                       the node to which this edge points
     */
    public Node getTo() {
        return m_to;
    }
    
    /**
     * Sets the node from which this edge points.
     *
     * @param                       the node from which this edge points
     */
    public void setFrom(Node theNode){
        m_from = theNode;
    }
    
    /**
     * Sets the node from which to edge points.
     *
     * @param                       the node to which this edge points
     */
    public void setTo(Node theNode){
        m_to = theNode;
    }
    
    /**
     * Returns the label of this node.
     *
     * @return                      the label of the node
     */
    public String getLabels() {
        return toString();
    }
    /**
     * Returns the length of this edge.
     *
     * @return                      the ledge of the edge
     */
    public double getLength() {
        return 40;
    }
    
    public boolean equals(Object obj) {
        if (!(obj instanceof DefaultEdge)){
            return false;
        }
        DefaultEdge otherEdge = (DefaultEdge) obj;
        return otherEdge.getFrom().equals(getFrom()) && otherEdge.getTo().equals(getTo());
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?