Package dev.roanh.gmark.util
Class UniqueGraph.GraphNode<V,E>
java.lang.Object
dev.roanh.gmark.util.UniqueGraph.GraphNode<V,E>
- Type Parameters:
V
- The type of data stored at the graph nodes.E
- The type of data stored at the graph edges.
- All Implemented Interfaces:
IDable
- Enclosing class:
- UniqueGraph<V,
E>
Represents a single node in the graph that is
uniquely identifiable by some data.
-
Field Summary
Modifier and TypeFieldDescriptionprivate V
The data stored at this node, this also uniquely identifies this node in the entire graph.private UniqueGraph<V,
E> The graph this node is in.private final int
The unique ID of this node.private Set<UniqueGraph.GraphEdge<V,
E>> The edges ending at this node.private Set<UniqueGraph.GraphEdge<V,
E>> The edges departing from this node. -
Constructor Summary
ModifierConstructorDescriptionprivate
GraphNode
(int id, UniqueGraph<V, E> graph, V data) Constructs a new graph node for the given graph and with the given data that uniquely identifies this node in the entire graph. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addUniqueEdgeFrom
(UniqueGraph.GraphNode<V, E> source) Adds a new unique edge without any label to this node from the given source node to connect from.void
addUniqueEdgeFrom
(UniqueGraph.GraphNode<V, E> source, E data) Adds a new unique edge with the given label data to this node from the given source node to connect from.void
addUniqueEdgeFrom
(V source) Adds a new unique edge without any label to this node from the existing node associated with the given source data.void
addUniqueEdgeFrom
(V source, E data) Adds a new unique edge with the given label data to this node from the existing node associated with the given source data.void
addUniqueEdgeTo
(UniqueGraph.GraphNode<V, E> target) Adds a new unique edge without any label from this node to the given target node to connect to.void
addUniqueEdgeTo
(UniqueGraph.GraphNode<V, E> target, E data) Adds a new unique edge with the given label data from this node to the given target node to connect to.void
addUniqueEdgeTo
(V target) Adds a new unique edge without any label from this node to the existing node associated with the given target data.void
addUniqueEdgeTo
(V target, E data) Adds a new unique edge with the given label data from this node to the existing node associated with the given target data.boolean
getData()
Gets the data stored at this node.Gets the unlabelled edge connecting this node and the node associated with the given target data.Gets the edge with the given label data connecting this node and the node associated with the given target data.int
getID()
Gets the unique ID for this object.int
Gets the total number of incoming edges this node has.Gets all the incoming edges for this node.int
Gets the total number of outgoing edges this node has.Gets all the outgoing edges for this node.int
hashCode()
void
remove()
Removes this node from the graph.void
rename
(UniqueGraph.GraphNode<V, E> replacement) Renames this node to the given replacement node.toString()
-
Field Details
-
id
private final int idThe unique ID of this node.- See Also:
-
graph
The graph this node is in. -
out
The edges departing from this node. -
in
The edges ending at this node. -
data
The data stored at this node, this also uniquely identifies this node in the entire graph.
-
-
Constructor Details
-
GraphNode
Constructs a new graph node for the given graph and with the given data that uniquely identifies this node in the entire graph.- Parameters:
id
- The ID of this graph node.graph
- The graph this node belongs to.data
- The data associated with this node that uniquely identifies it in the graph.
-
-
Method Details
-
rename
Renames this node to the given replacement node. This procedure will remove this node from the graph and move all edges originally attached to this node to the given replacement node.- Parameters:
replacement
- The replacement node.
-
getID
public int getID()Gets the unique ID for this object. This ID uniquely identifies all objects of this type.Note that the uniqueness of a graph node is still dependent on the data stored at this node and that therefore two nodes with the same data but different IDs are in fact still equal. However, this ID can be useful for other applications where an ordering on the graph nodes is required. In addition, if no nodes are ever removed from the graph then the ordered IDs of all nodes in the graph form an unbroken sequence from 0 to
UniqueGraph.getNodeCount()
- 1. -
remove
public void remove()Removes this node from the graph. After removal it will still reference other remaining graph nodes.
Note: calling this function while iterating over the nodes or edges in the graph will cause a co-modification exception. For mass removal of nodes useUniqueGraph.removeNodeIf(Predicate)
instead.- See Also:
-
getEdgeTo
Gets the unlabelled edge connecting this node and the node associated with the given target data.- Parameters:
target
- The data to identify the target node.- Returns:
- The edge connecting this node and target node
or
null
if no such node exists.
-
getEdgeTo
Gets the edge with the given label data connecting this node and the node associated with the given target data.- Parameters:
target
- The data to identify the target node.data
- The edge label data.- Returns:
- The edge connecting this node and target node
or
null
if no such node exists.
-
getOutCount
public int getOutCount()Gets the total number of outgoing edges this node has.- Returns:
- The total number of outgoing edges this node has.
-
getInCount
public int getInCount()Gets the total number of incoming edges this node has.- Returns:
- The total number of incoming edges this node has.
-
getOutEdges
Gets all the outgoing edges for this node.- Returns:
- All the outgoing edges for this node.
-
getInEdges
Gets all the incoming edges for this node.- Returns:
- All the incoming edges for this node.
-
addUniqueEdgeFrom
Adds a new unique edge with the given label data to this node from the given source node to connect from.- Parameters:
source
- The source node to add an edge from.data
- The edge label data.
-
addUniqueEdgeFrom
Adds a new unique edge with the given label data to this node from the existing node associated with the given source data.- Parameters:
source
- The data to identify the node to connect from with.data
- The edge label data.
-
addUniqueEdgeFrom
Adds a new unique edge without any label to this node from the given source node to connect from.- Parameters:
source
- The source node to add an edge from.
-
addUniqueEdgeFrom
Adds a new unique edge without any label to this node from the existing node associated with the given source data.- Parameters:
source
- The data to identify the node to connect from with.
-
addUniqueEdgeTo
Adds a new unique edge with the given label data from this node to the given target node to connect to.- Parameters:
target
- The target node to add an edge to.data
- The edge label data.
-
addUniqueEdgeTo
Adds a new unique edge with the given label data from this node to the existing node associated with the given target data.- Parameters:
target
- The data to identify the node to connect to with.data
- The edge label data.
-
addUniqueEdgeTo
Adds a new unique edge without any label from this node to the given target node to connect to.- Parameters:
target
- The target node to add an edge to.
-
addUniqueEdgeTo
Adds a new unique edge without any label from this node to the existing node associated with the given target data.- Parameters:
target
- The data to identify the node to connect to with.
-
getData
Gets the data stored at this node. The returned data uniquely identifies this node in the entire graph.- Returns:
- The data stored at this node.
-
toString
-
equals
-
hashCode
public int hashCode()
-