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

com.yworks.util.graph.Node Maven / Gradle / Ivy

Go to download

The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts

There is a newer version: 4.1.1
Show newest version
package com.yworks.util.graph;

import com.google.common.graph.Network;

import java.util.Iterator;
import java.util.Set;

public class Node {
    private Network network;

    public Node(Network network) {
        this.network = network;
    }

    /**
     * Returns all outgoing edges of this node.
     * @return {Set}
     */
    public Set outEdges() {
        return this.network.outEdges(this);
    }

    /**
     * Returns all ingoing edges of this node.
     * @return {Set}
     */
    public Set inEdges() {
        return this.network.inEdges(this);
    }

    /**
     * Returns the first outgoing edge for this node, if any.
     * @return {Edge|null}
     */
    public Edge firstOutEdge() {
        Iterator outEdgesIterator = this.network.outEdges(this).iterator();
        if (outEdgesIterator.hasNext()) {
            return outEdgesIterator.next();
        }
        return null;
    }

    /**
     * Returns the first ingoing edge for this node, if any.
     * @return {Edge|null}
     */
    public Edge firstInEdge() {
        Iterator inEdgesIterator = this.network.inEdges(this).iterator();
        if (inEdgesIterator.hasNext()) {
            return inEdgesIterator.next();
        }
        return null;
    }

    /**
     * Returns the edge directly connecting to this node, if any.
     * @param node - the node which you would like to know the edge for.
     * @return {Edge|null}
     */
    public Edge getEdgeTo(Node node) {
        Set connectingEdges = this.network.edgesConnecting(this, node);
        if (connectingEdges.iterator().hasNext()) {
            return connectingEdges.iterator().next();
        }
        return null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy