1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package triptracker.core;
21
22 import java.util.Date;
23
24 /***
25 * Route represents a stored route on the server with a route ID, user ID and
26 * description. Data in a Route object is immutable.
27 */
28 public class Route {
29 private final int routeId;
30 private final int userId;
31 private final String description;
32 private final Date lastUpdate;
33 private boolean active = true;
34 private boolean visible = false;
35
36 public Route(int routeId) {
37 this(routeId, 0, "RouteId = " + routeId, true, null);
38 }
39
40 public Route(int routeId, int userId, String description) {
41 this(routeId, userId, description, true, null);
42 }
43
44 public Route(int routeId, int userId, String description, boolean active,
45 Date date) {
46 this(routeId, userId, description, active, false, date);
47 }
48
49 public Route(int routeId, int userId, String description, boolean active,
50 boolean visible, Date date) {
51 this.routeId = routeId;
52 this.userId = userId;
53 this.description = description;
54 this.lastUpdate = date;
55 this.active = active;
56 this.visible = visible;
57 }
58
59 public String getDescription() {
60 return description;
61 }
62
63 public int getRouteId() {
64 return routeId;
65 }
66
67 public int getUserId() {
68 return userId;
69 }
70
71 public String getLastUpdateString() {
72 if (lastUpdate == null) {
73 return "";
74 } else {
75 return Utils.dateToString(lastUpdate);
76 }
77 }
78
79 /***
80 * Returns the date and time of the last
81 *
82 * @return date of last update
83 */
84 public Date getLastUpdate() {
85 return lastUpdate;
86 }
87
88 /***
89 * Returns the active state of the route.
90 *
91 * @return active state of route
92 */
93 public boolean isActive(){
94 return active;
95 }
96
97 /***
98 * Set route state to activated or deactivated.
99 *
100 * @param active true to activate, false to deactivate
101 */
102 public void setActive(boolean active) {
103 this.active = active;
104 }
105
106 public boolean getVisible() {
107 return visible;
108 }
109
110 /***
111 * Set the visibility of the route to other clients.
112 *
113 * @param visibility
114 */
115 public void setVisible(boolean visibility) {
116 this.visible = visibility;
117 }
118
119 @Override
120 public String toString() {
121 if (getDescription().length() > 25) {
122 return getDescription().substring(0, 25);
123 } else {
124 return getDescription();
125 }
126 }
127 }