Package org.insa.graphs.model
Class Node
java.lang.Object
org.insa.graphs.model.Node
- All Implemented Interfaces:
java.lang.Comparable<Node>
public final class Node extends java.lang.Object implements java.lang.Comparable<Node>
Class representing a Node in a Graph.
This class holds information regarding nodes in the graph together with the successors associated to the nodes.
Nodes are comparable based on their ID.
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description intcompareTo(Node other)Compare the ID of this node with the ID of the given node.booleanequals(java.lang.Object other)intgetId()intgetNumberOfSuccessors()PointgetPoint()java.util.List<Arc>getSuccessors()booleanhasSuccessors()static ArclinkNodes(Node origin, Node destination, float length, RoadInformation roadInformation, java.util.ArrayList<Point> points)Link the two given nodes with one or two arcs (depending on roadInformation), with the given attributes.
-
Constructor Details
-
Node
Create a new Node with the given ID corresponding to the given Point with an empty list of successors.- Parameters:
id- ID of the node.point- Position of the node.
-
-
Method Details
-
linkNodes
public static Arc linkNodes(Node origin, Node destination, float length, RoadInformation roadInformation, java.util.ArrayList<Point> points)Link the two given nodes with one or two arcs (depending on roadInformation), with the given attributes.
If
roadInformation.isOneWay()istrue, only a forward arc is created (origin to destination) and added to origin. Otherwise, a corresponding backward arc is created and add to destination.- Parameters:
origin- Origin of the arc.destination- Destination of the arc.length- Length of the arc.roadInformation- Information corresponding to the arc.points- Points for the arc.- Returns:
- The newly created forward arc (origin to destination).
-
getId
public int getId()- Returns:
- ID of this node.
-
getNumberOfSuccessors
public int getNumberOfSuccessors()- Returns:
- Number of successors of this node.
-
hasSuccessors
public boolean hasSuccessors()- Returns:
- true if this node has at least one successor.
-
getSuccessors
- Returns:
- List of successors of this node (unmodifiable list).
- See Also:
Collections.unmodifiableList(List)
-
getPoint
- Returns:
- Location of this node.
-
equals
public boolean equals(java.lang.Object other)- Overrides:
equalsin classjava.lang.Object
-
compareTo
Compare the ID of this node with the ID of the given node.- Specified by:
compareToin interfacejava.lang.Comparable<Node>- Parameters:
other- Node to compare this node with.- See Also:
Comparable.compareTo(java.lang.Object)
-