
com.yworks.util.graph.Node Maven / Gradle / Ivy
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 - 2025 Weber Informatics LLC | Privacy Policy