View Javadoc

1   /*
2    * Trip Tracker, a real-time position tracking system for the Internet.
3    * Copyright (C) 2006  Team Trip Tracker
4    *
5    * This program is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License as published by the
7    * Free Software Foundation; either version 2 of the License, or (at your
8    * option) any later version.
9    *
10   * This program is distributed in the hope that it will be useful, but
11   * WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13   * General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License along
16   * with this program; if not, write to the Free Software Foundation, Inc.,
17   * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
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 }