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.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addSuccessor(Arc arc)
Add a successor to this node.int
compareTo(Node other)
Compare the ID of this node with the ID of the given node.boolean
equals(java.lang.Object other)
int
getId()
int
getNumberOfSuccessors()
Point
getPoint()
java.util.List<Arc>
getSuccessors()
boolean
hasSuccessors()
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.
-
-
-
Constructor Detail
-
Node
public Node(int id, Point point)
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 Detail
-
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).
-
addSuccessor
protected void addSuccessor(Arc arc)
Add a successor to this node.- Parameters:
arc
- Arc to the successor.
-
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
public java.util.List<Arc> getSuccessors()
- Returns:
- List of successors of this node (unmodifiable list).
- See Also:
Collections.unmodifiableList(List)
-
getPoint
public Point getPoint()
- Returns:
- Location of this node.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
-