-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRoutes.java
97 lines (85 loc) · 2.37 KB
/
Routes.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
/*
Routes.java
Author: Shreyas Jayanna
Version 1
Date: 05/15/2015
*/
// Import statement
import java.util.HashMap;
/**
* Class Routes. This class stores traffic density and time taken to travel the route for every route.
*/
public class Routes {
HashMap<String,Integer> routeDensity; // <route id, num of vehicles on the route>
HashMap<String,Double> routeTime; // Time taken to travel the entire route
/**
* Default constructor
*/
public Routes() {
this.routeDensity = new HashMap<>();
this.routeTime = new HashMap<>();
}
/**
* This method returns the route density hashmap
* @return
*/
public HashMap<String, Integer> getRouteDensity() {
return routeDensity;
}
/**
* This method sets the route density hashmap to the passed hashmap
* @param routeDensity route density hashmap
*/
public void setRouteDensity(HashMap<String, Integer> routeDensity) {
this.routeDensity = routeDensity;
}
/**
* This method returns the time taken to travel on the route.
* @return Time taken to travel the route
*/
public HashMap<String, Double> getRouteTime() {
return routeTime;
}
/**
* This method increases route density by 1
* @param id Route ID
*/
public void addRouteDensity(String id) {
if(this.routeDensity.containsKey(id)) {
this.routeDensity.put(id, (this.routeDensity.get(id) + 1));
} else {
this.routeDensity.put(id, 1);
}
}
/**
* This method returns the route density of a particular route.
* @param id Route ID
* @return Traffic density on the route
*/
public int getRouteDensity(String id) {
if(this.routeDensity.containsKey(id))
return this.routeDensity.get(id);
return 0;
}
/**
* This method adds the travel time on the route.
* @param id Route ID
* @param time Time taken to travel the route
*/
public void addRouteTime(String id, double time) {
if(this.routeTime.containsKey(id))
this.routeTime.put(id, this.routeTime.get(id) + time);
else
this.routeTime.put(id,time);
}
/**
* This method returns the time taken to travel the route.
* @param id Route ID
* @return Time taken to travel the route
*/
public double getRouteTime(String id) {
if(this.routeTime.containsKey(id))
return this.routeTime.get(id);
return 0.00;
}
}