-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTravelMap.java
More file actions
96 lines (77 loc) · 2.15 KB
/
TravelMap.java
File metadata and controls
96 lines (77 loc) · 2.15 KB
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
package model;
import graph.Edge;
import graph.Node;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
public class TravelMap {
private List<Node> nodes = new LinkedList<>();
private List<Edge> edges = new LinkedList<>();
/**
* Default constructor for model.TravelMap
*/
public TravelMap() {
}
/**
* method for adding an edge to the travel map
*
* @param node1 starting node of the edge
* @param node2 ending node of the edge
* @param cost the cost of the edge
*/
public void addEdge(Node node1, Node node2, int cost) {
Edge temporaryEdge = new Edge(node1, node2, cost);
edges.add(temporaryEdge);
}
/**
* method for adding either a oneWay or a twoWay edge
*
* @param node1 Starting graph.Edge
* @param node2 Ending graph.Edge
* @param cost the cost of the edge
* @param isTwoWay true if it is a twoWay edge false if it is a oneWay edge
*/
public void addEdge(Node node1, Node node2, int cost, boolean isTwoWay) {
Edge temporaryEdge = new Edge(node1, node2, cost, isTwoWay);
edges.add(temporaryEdge);
}
public void addNode(Node node) {
nodes.add(node);
}
/**
* Getter for nodes
*
* @return a string containing all of nodes
*/
public String getNodesToString() {
StringBuilder allNodes = new StringBuilder();
for (Node node : nodes) {
allNodes.append(" ").append(node.toString()).append("\n");
}
return allNodes.toString();
}
public List<Node> getNodes() {
return this.nodes;
}
public void setNodes(ArrayList<Node> nodes) {
this.nodes = nodes;
}
/**
* Getter for edges
*
* @return a list for edges
*/
public List<Edge> getEdges() {
return edges;
}
public void setEdges(ArrayList<Edge> edges) {
this.edges = edges;
}
@Override
public String toString() {
return "TravelMap{" +
"nodes=" + nodes.toString() +
", edges=" + edges.toString() +
'}';
}
}