Class TLcdGraph<N,E>

java.lang.Object
com.luciad.network.graph.TLcdGraph<N,E>
All Implemented Interfaces:
ILcdEditableGraph<N,E>, ILcdGraph<N,E>

public class TLcdGraph<N,E> extends Object implements ILcdEditableGraph<N,E>
Implementation of ILcdGraph. This implementation uses equals() and hashCode() to identify the nodes and edges it contains - a correct implementation of both methods is thus required for all edges and nodes contained in this graph.
Since:
5.1
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new, empty graph.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addEdge(E aEdge, N aStartNode, N aEndNode, int aFireEventMode)
    Adds an edge to this graph, connecting the two given nodes.
    void
    Registers the given ILcdGraphListener with this graph.
    void
    addNode(N aNode, int aFireEventMode)
    Adds a node to this graph.
    boolean
    canAddEdge(E aEdge, N aStartNode, N aEndNode)
    Returns true if the given edge can be added to this graph, false otherwise.
    boolean
    canAddNode(N aNode)
    Returns true if the given node can be added to this graph, false otherwise.
    boolean
    Returns true if the given edge can be removed from this graph, false otherwise.
    boolean
    Returns true if the given node can be removed from this graph, false otherwise.
    void
    clear(int aFireEventMode)
    Clears the graph; all edges and nodes are removed.
    boolean
    containsEdge(E aEdge)
    Returns true if aEdge is contained in this graph, false otherwise.
    boolean
    containsNode(N aNode)
    Returns true if aNode is part of this graph, false otherwise.
    void
    edgeChanged(E aEdge, int aEventMode)
    This method should be called when the given edge has changed.
    void
    edgesChanged(Vector<E> aEdges, int aEventMode)
    This method should be called when the given edges have changed.
    void
    Fires all the collected graph changes, i.e., all graph events that have been generated using the the ILcdFireEventMode.FIRE_LATER mode, after the previous call to fireCollectedGraphChanges().
    Returns an Enumeration containing all edges in this graph.
    getEdges(N aNode)
    Returns an Enumeration containing all edges connected to the given node.
    getEndNode(E aEdge)
    Returns the end node of the given edge in this graph.
    Returns an Enumeration containing all nodes in this graph.
    getOppositeNode(E aEdge, N aNode)
    If aNode is one of the two nodes connected by the given edge in this graph, returns the other node, otherwise throws IllegalArgumentException.
    getStartNode(E aEdge)
    Returns the start node of the given edge in this graph.
    boolean
    isConnected(E aEdge, N aNode)
    Returns true if aNode is one the nodes to which this edge is connected.
    void
    nodeChanged(N aNode, int aEventMode)
    This method should be called when the given node has changed.
    void
    nodesChanged(Vector<N> aNodes, int aEventMode)
    This method should be called when the given nodes have changed.
    removeEdge(E aEdge, int aFireEventMode)
    Removes an edge from this graph.
    void
    removeEdges(int aFireEventMode)
    Removes all edges from this graph - nodes will remain in the graph.
    void
    Unregisters the given ILcdGraphListener from this graph.
    removeNode(N aNode, int aFireEventMode)
    Removes a node from this graph.
    Returns a general description of this graph, containing the number of nodes and edges contained in this graph.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • TLcdGraph

      public TLcdGraph()
      Constructs a new, empty graph.
  • Method Details

    • containsNode

      public boolean containsNode(N aNode)
      Description copied from interface: ILcdGraph
      Returns true if aNode is part of this graph, false otherwise.
      Specified by:
      containsNode in interface ILcdGraph<N,E>
      Parameters:
      aNode - the node to be checked.
      Returns:
      true if aNode is part of the graph, false otherwise.
    • getNodes

      public Enumeration<N> getNodes()
      Description copied from interface: ILcdGraph
      Returns an Enumeration containing all nodes in this graph.
      Specified by:
      getNodes in interface ILcdGraph<N,E>
      Returns:
      an Enumeration containing all nodes in this graph.
    • containsEdge

      public boolean containsEdge(E aEdge)
      Description copied from interface: ILcdGraph
      Returns true if aEdge is contained in this graph, false otherwise.
      Specified by:
      containsEdge in interface ILcdGraph<N,E>
      Parameters:
      aEdge - the edge to be checked
      Returns:
      true if aEdge is part of the graph, false otherwise.
    • getEdges

      public Enumeration<E> getEdges()
      Description copied from interface: ILcdGraph
      Returns an Enumeration containing all edges in this graph.
      Specified by:
      getEdges in interface ILcdGraph<N,E>
      Returns:
      an Enumeration containing all edges in this graph.
    • getEdges

      public Enumeration<E> getEdges(N aNode)
      Description copied from interface: ILcdGraph
      Returns an Enumeration containing all edges connected to the given node.
      Specified by:
      getEdges in interface ILcdGraph<N,E>
      Parameters:
      aNode - the node whose connected edges should be returned.
      Returns:
      an Enumeration containing all edges connected to the given node.
    • getStartNode

      public N getStartNode(E aEdge)
      Description copied from interface: ILcdGraph
      Returns the start node of the given edge in this graph.
      Specified by:
      getStartNode in interface ILcdGraph<N,E>
      Parameters:
      aEdge - the edge whose start node should be returned.
      Returns:
      the start node.
    • getEndNode

      public N getEndNode(E aEdge)
      Description copied from interface: ILcdGraph
      Returns the end node of the given edge in this graph.
      Specified by:
      getEndNode in interface ILcdGraph<N,E>
      Parameters:
      aEdge - the edge whose end node should be returned.
      Returns:
      the end node.
    • getOppositeNode

      public N getOppositeNode(E aEdge, N aNode)
      Description copied from interface: ILcdGraph
      If aNode is one of the two nodes connected by the given edge in this graph, returns the other node, otherwise throws IllegalArgumentException.
      Specified by:
      getOppositeNode in interface ILcdGraph<N,E>
      Parameters:
      aEdge - the edge whose opposite node should be returned.
      aNode - one of the two Object's connected by the given edge.
      Returns:
      if aNode is one of the two nodes connected by this edge, returns the other node connected by this edge.
    • isConnected

      public boolean isConnected(E aEdge, N aNode)
      Description copied from interface: ILcdGraph
      Returns true if aNode is one the nodes to which this edge is connected.
      Specified by:
      isConnected in interface ILcdGraph<N,E>
      Parameters:
      aEdge - the edge whose connectivity should be checked.
      aNode - the node whose connectivity should be checked.
      Returns:
      true if aNode is one the nodes to which this edge is connected.
    • addGraphListener

      public void addGraphListener(ILcdGraphListener<N,E> aGraphListener)
      Description copied from interface: ILcdGraph
      Registers the given ILcdGraphListener with this graph. All events generated by this graph afterwards will be sent to the given listener, until it is removed from this graph.
      Specified by:
      addGraphListener in interface ILcdGraph<N,E>
      Parameters:
      aGraphListener - the graph listener to be registered with this graph.
    • removeGraphListener

      public void removeGraphListener(ILcdGraphListener<N,E> aGraphListener)
      Description copied from interface: ILcdGraph
      Unregisters the given ILcdGraphListener from this graph. After it has been unregistered, no events generated by this graph will be sent to the given listener anymore.
      Specified by:
      removeGraphListener in interface ILcdGraph<N,E>
      Parameters:
      aGraphListener - the graph listener to be unregistered from this graph.
    • canAddNode

      public boolean canAddNode(N aNode)
      Description copied from interface: ILcdEditableGraph
      Returns true if the given node can be added to this graph, false otherwise. More specifically, a node can be added to this graph if the following conditions are met:
      • the node is not null
      • the node is not yet part of this graph
      • the node satisfies all additional implementation-specific requirements (see the documentation of the implementing class).
      Specified by:
      canAddNode in interface ILcdEditableGraph<N,E>
      Parameters:
      aNode - the node to be verified.
      Returns:
      true if the node can be added to this graph, false otherwise.
    • addNode

      public void addNode(N aNode, int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Adds a node to this graph.
      Specified by:
      addNode in interface ILcdEditableGraph<N,E>
      Parameters:
      aNode - the node to be added to this graph.
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      canAddNode(aNode) - Note: this validation is potentially expensive, and should be avoided whenever possible.
    • canRemoveNode

      public boolean canRemoveNode(N aNode)
      Description copied from interface: ILcdEditableGraph
      Returns true if the given node can be removed from this graph, false otherwise. More specifically, a node can be remove from this graph if the following conditions are met:
      • the node is not null
      • the node is part of this graph
      • there are no edges in this graph, connected to the node
      Specified by:
      canRemoveNode in interface ILcdEditableGraph<N,E>
      Parameters:
      aNode - the node to be verified.
      Returns:
      true if the node can be removed from this graph, false otherwise.
    • removeNode

      public N removeNode(N aNode, int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Removes a node from this graph.
      Specified by:
      removeNode in interface ILcdEditableGraph<N,E>
      Parameters:
      aNode - the node to be removed from this graph.
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      canRemoveNode(aNode) - Note: this validation is potentially expensive, and should be avoided whenever possible.
      Returns:
      the node that was removed from the graph.
    • canAddEdge

      public boolean canAddEdge(E aEdge, N aStartNode, N aEndNode)
      Description copied from interface: ILcdEditableGraph
      Returns true if the given edge can be added to this graph, false otherwise. More specifically, an edge can be added to this graph if the following conditions are met:
      • none of the arguments is null
      • the edge is not yet part of this graph
      • both nodes are part of this graph
      • the edge satisfies all additional implementation-specific requirements (see the documentation of the implementing class).
      Specified by:
      canAddEdge in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdge - the edge to be verified.
      aStartNode - the first node that should be connected by the given edge.
      aEndNode - the second node that should be connected by the given edge.
      Returns:
      true if the edge can be added to this graph, false otherwise.
    • addEdge

      public void addEdge(E aEdge, N aStartNode, N aEndNode, int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Adds an edge to this graph, connecting the two given nodes.
      Specified by:
      addEdge in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdge - the edge to be added to this graph.
      aStartNode - the first node that should be connected by the given edge.
      aEndNode - the second node that should be connected by the given edge.
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      canAddEdge(aEdge, aStartNode, aEndNode) - Note: this validation is potentially expensive, and should be avoided whenever possible.
    • canRemoveEdge

      public boolean canRemoveEdge(E aEdge)
      Description copied from interface: ILcdEditableGraph
      Returns true if the given edge can be removed from this graph, false otherwise. More specifically, a edge can be remove from this graph if the following conditions are met:
      • the edge is not null
      • the edge is part of this graph
      Specified by:
      canRemoveEdge in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdge - the edge to be verified.
      Returns:
      true if the edge can be removed from this graph, false otherwise.
    • removeEdge

      public E removeEdge(E aEdge, int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Removes an edge from this graph.
      Specified by:
      removeEdge in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdge - the edge to be removed from this graph.
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      canRemoveEdge(aEdge) - Note: this validation is potentially expensive, and should be avoided whenever possible.
      Returns:
      the edge which was removed from the graph.
    • removeEdges

      public void removeEdges(int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Removes all edges from this graph - nodes will remain in the graph.
      Specified by:
      removeEdges in interface ILcdEditableGraph<N,E>
      Parameters:
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
    • clear

      public void clear(int aFireEventMode)
      Description copied from interface: ILcdEditableGraph
      Clears the graph; all edges and nodes are removed.
      Specified by:
      clear in interface ILcdEditableGraph<N,E>
      Parameters:
      aFireEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
    • fireCollectedGraphChanges

      public void fireCollectedGraphChanges()
      Description copied from interface: ILcdEditableGraph
      Fires all the collected graph changes, i.e., all graph events that have been generated using the the ILcdFireEventMode.FIRE_LATER mode, after the previous call to fireCollectedGraphChanges(). Note that a fireCollectedGraphChanges() call is made whenever a graph event is generated in the ILcdFireEventMode.FIRE_NOW, to guarantee the correct order of the events.
      Specified by:
      fireCollectedGraphChanges in interface ILcdEditableGraph<N,E>
    • nodeChanged

      public void nodeChanged(N aNode, int aEventMode)
      Description copied from interface: ILcdEditableGraph
      This method should be called when the given node has changed.
      Preconditions:
      containsPartition(aNode) - Note: this validation is potentially expensive, and should be avoided whenever possible.
      Specified by:
      nodeChanged in interface ILcdEditableGraph<N,E>
      Parameters:
      aNode - the node that has changed.
      aEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
    • nodesChanged

      public void nodesChanged(Vector<N> aNodes, int aEventMode)
      Description copied from interface: ILcdEditableGraph
      This method should be called when the given nodes have changed.
      Specified by:
      nodesChanged in interface ILcdEditableGraph<N,E>
      Parameters:
      aNodes - a vector containing the nodes that have changed.
      aEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      for each node object in the given vector should hold that: containsPartition(node) - Note: this validation is potentially expensive, and should be avoided whenever possible.
    • edgeChanged

      public void edgeChanged(E aEdge, int aEventMode)
      Description copied from interface: ILcdEditableGraph
      This method should be called when the given edge has changed.
      Specified by:
      edgeChanged in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdge - the edge that has changed.
      aEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      containsBoundaryEdge(aEdge) - Note: this validation is potentially expensive, and should be avoided whenever possible.
    • edgesChanged

      public void edgesChanged(Vector<E> aEdges, int aEventMode)
      Description copied from interface: ILcdEditableGraph
      This method should be called when the given edges have changed.
      Specified by:
      edgesChanged in interface ILcdEditableGraph<N,E>
      Parameters:
      aEdges - a vector containing the edges that have changed.
      aEventMode - the mode for sending out the TLcdGraphChangedEvent. This can be one of ILcdFireEventMode.FIRE_NOW, ILcdFireEventMode.FIRE_LATER or ILcdFireEventMode.NO_EVENT.
      Preconditions:
      for each edge object in the given vector should hold that: containsBoundaryEdge(edge) - Note: this validation is potentially expensive, and should be avoided whenever possible.
    • toString

      public String toString()
      Returns a general description of this graph, containing the number of nodes and edges contained in this graph. The exact details of the representation are unspecified and are subject to change.
      Overrides:
      toString in class Object