connection.java

来自「jboss规则引擎」· Java 代码 · 共 80 行

JAVA
80
字号
package org.drools.ide.editors.rete.model;

import org.drools.reteoo.BaseVertex;

/**
 * A connection between two distinct vertices.
 */
public class Connection extends ModelElement {

    private boolean    isConnected;

    private BaseVertex source;

    private BaseVertex target;

    /** 
     * Creating a connection between two distinct vertices.
     * 
     * @param source a source endpoint
     * @param target a target endpoint
     * @throws IllegalArgumentException if any of the parameters are null or source == target
     */
    public Connection(BaseVertex source,
                      BaseVertex target) {
        this.source = source;
        this.target = target;
        source.addConnection( this );
        target.addConnection( this );
        isConnected = true;
    }

    /** 
     * Disconnect this connection from the vertices it is attached to.
     */
    public void disconnect() {
        if ( isConnected ) {
            source.removeConnection( this );
            target.removeConnection( this );
            isConnected = false;
        }
    }

    /**
     * Returns the source endpoint of this connection.
     * 
     * @return BaseVertex vertex
     */
    public BaseVertex getSource() {
        return source;
    }

    /**
     * Returns the target endpoint of this connection.
     * 
     * @return BaseVertex vertex
     */
    public BaseVertex getTarget() {
        return target;
    }

    /**
     * Gets opposite of specified vertex.
     * 
     * Returning <code>null</code> if specified not does not belong into this connection.
     * 
     * @param vertex
     * @return opposite of vertex
     */
    public BaseVertex getOpposite(BaseVertex vertex) {
        // If null or not part of this connection
        if ( vertex == null || (!vertex.equals( getSource() ) && !vertex.equals( getTarget() )) ) {
            return null;
        }
        if ( vertex.equals( getSource() ) ) {
            return getTarget();
        }
        return getSource();
    }

}

⌨️ 快捷键说明

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