Modifier and Type | Field and Description |
---|---|
static int |
NOT_NEIGHBOR
A value that can be used if a cost is needed
even if the GraphNode is not a neighbor of a node.
|
Constructor and Description |
---|
GraphNode(java.lang.String name)
Represents a valid location in the game graph.
|
Modifier and Type | Method and Description |
---|---|
void |
addNeighbor(GraphNode neighbor,
int cost)
Maintains sorted order of neighbors by neighbor name.
|
int |
compareTo(GraphNode otherNode)
Return the results of comparing this node's name to the other node's name.
|
void |
displayCostToEachNeighbor()
Prints a list of neighbors of this GraphNode and the cost of the edge to them
|
int |
getCostTo(java.lang.String neighborName) |
GraphNode |
getNeighbor(java.lang.String name) |
java.util.Iterator<java.lang.String> |
getNeighborNames()
Returns and iterator that can be used to find neighbors of
this GraphNode.
|
java.util.List<Neighbor> |
getNeighbors()
Returns a list of the neighbors of this GraphNode instance.
|
java.lang.String |
getNodeName()
Return the name of this GraphNode.
|
boolean |
getSpycam() |
boolean |
isNeighbor(java.lang.String neighborName)
Returns true if this node name is a neighbor of current node.
|
void |
printNeighborNames()
Display's the node name followed by a list of neighbors to this node.
|
void |
setSpycam(boolean cam) |
java.lang.String |
toString() |
public static final int NOT_NEIGHBOR
In Dijkstra's algorithm, initializing a node to a high cost (Integer.MAX_VALUE) can be used to indicate a node is not a neighbor, or not connected by a path to the starting node.
There is no requirement to use this constant.
public GraphNode(java.lang.String name)
name
- The label that uniquely identifies this graph node.public java.lang.String getNodeName()
public java.util.List<Neighbor> getNeighbors()
public boolean isNeighbor(java.lang.String neighborName)
neighborName
- to look forpublic void addNeighbor(GraphNode neighbor, int cost)
neighbor
- An adjacent node (a neighbor)cost
- The cost to move to that node (from this node)public java.util.Iterator<java.lang.String> getNeighborNames()
public boolean getSpycam()
public void setSpycam(boolean cam)
cam
- indicates whether the node now has a spycampublic int getCostTo(java.lang.String neighborName) throws NotNeighborException
neighborName
- name of potential neighborNotNeighborException
- if neighborName is not a neighborpublic GraphNode getNeighbor(java.lang.String name) throws NotNeighborException
name
- name of potential neighborNotNeighborException
- if name is not a neighbor of the GraphNodepublic void displayCostToEachNeighbor()
1 b 4 c 20 d 1 f
public int compareTo(GraphNode otherNode)
compareTo
in interface java.lang.Comparable<GraphNode>
otherNode
- Another node to compare names with this node.public java.lang.String toString()
toString
in class java.lang.Object
public void printNeighborNames()
1 b 4 c 20 d 1 f