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>

public static class UniqueGraph.GraphNode<V,E> extends Object implements IDable
Represents a single node in the graph that is uniquely identifiable by some data.
  • Field Details

    • id

      private final int id
      The unique ID of this node.
      See Also:
    • graph

      private UniqueGraph<V,E> graph
      The graph this node is in.
    • out

      private Set<UniqueGraph.GraphEdge<V,E>> out
      The edges departing from this node.
    • in

      private Set<UniqueGraph.GraphEdge<V,E>> in
      The edges ending at this node.
    • data

      private V data
      The data stored at this node, this also uniquely identifies this node in the entire graph.
  • Constructor Details

    • GraphNode

      private 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.
      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

      public void rename(UniqueGraph.GraphNode<V,E> replacement)
      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.

      Specified by:
      getID in interface IDable
      Returns:
      The ID of this node.
      See Also:
    • 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 use UniqueGraph.removeNodeIf(Predicate) instead.
      See Also:
    • getEdgeTo

      public UniqueGraph.GraphEdge<V,E> getEdgeTo(V target)
      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

      public UniqueGraph.GraphEdge<V,E> getEdgeTo(V target, E data)
      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

      public Set<UniqueGraph.GraphEdge<V,E>> getOutEdges()
      Gets all the outgoing edges for this node.
      Returns:
      All the outgoing edges for this node.
    • getInEdges

      public Set<UniqueGraph.GraphEdge<V,E>> getInEdges()
      Gets all the incoming edges for this node.
      Returns:
      All the incoming edges for this node.
    • addUniqueEdgeFrom

      public 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.
      Parameters:
      source - The source node to add an edge from.
      data - The edge label data.
    • addUniqueEdgeFrom

      public 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.
      Parameters:
      source - The data to identify the node to connect from with.
      data - The edge label data.
    • addUniqueEdgeFrom

      public void 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.
      Parameters:
      source - The source node to add an edge from.
    • addUniqueEdgeFrom

      public 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.
      Parameters:
      source - The data to identify the node to connect from with.
    • addUniqueEdgeTo

      public 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.
      Parameters:
      target - The target node to add an edge to.
      data - The edge label data.
    • addUniqueEdgeTo

      public 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.
      Parameters:
      target - The data to identify the node to connect to with.
      data - The edge label data.
    • addUniqueEdgeTo

      public 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.
      Parameters:
      target - The target node to add an edge to.
    • addUniqueEdgeTo

      public 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.
      Parameters:
      target - The data to identify the node to connect to with.
    • getData

      public V 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

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object other)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object