-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMyNode.java
106 lines (92 loc) · 2.18 KB
/
MyNode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
MyNode.java
Author: Shreyas Jayanna
Version 1
Date: 05/15/2015
*/
// Import statements
import java.util.ArrayList;
import java.util.List;
/**
* Class MyNode. This class defines a node in the road network graph.
*/
public class MyNode {
String id;
List<MyEdge> edgeList = null;
List<MyNode> neighborNodes = null;
double distance;
MyNode prev;
/**
* Constructor
* @param id ID of the node
*/
public MyNode(String id) {
this.id = id;
edgeList = new ArrayList<MyEdge>();
neighborNodes = new ArrayList<MyNode>();
this.distance = Double.POSITIVE_INFINITY;
prev = null;
}
/**
* This method adds an edge to the edgelist
* @param edge Edge
*/
public void addEdgeList(MyEdge edge) {
this.edgeList.add(edge);
}
/**
* This method adds a neighbor to a node
* @param node Node
* @return True if successful
*/
public boolean addNeighbor(MyNode node) {
if(this.neighborNodes.add(node))
return true;
return false;
}
/**
* This method returns the ID of the node
* @return Node ID
*/
public String getId() {
return id;
}
/**
* This method returns the edge list
* @return Edge list
*/
public List<MyEdge> getEdgeList() {
return edgeList;
}
/**
* This method returns the neighbor nodes of a node.
* @return Neighbor nodes list
*/
public List<MyNode> getNeighborNodes() {
return this.neighborNodes;
}
/**
* This method sets the Id of the node
* @param id Node ID
*/
public void setId(String id) {
this.id = id;
}
/**
* This method adds an edge to the edgelist
* @param edge Edge
* @return True if successful
*/
public boolean addEdge(MyEdge edge) {
if(this.edgeList.add(edge))
return true;
return false;
}
/**
* This method sets the distance of the node from the source.
* @param distance Distance
*/
public void setDistance(double distance) {
this.distance = distance;
}
}