/
Trip.java
251 lines (196 loc) · 6.81 KB
/
Trip.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/* This file is based on code copied from project OneBusAway, see the LICENSE file for further information. */
package org.opentripplanner.model;
import javax.validation.constraints.NotNull;
public final class Trip extends TransitEntity {
private static final long serialVersionUID = 1L;
private Route route;
private Operator operator;
private FeedScopedId serviceId;
private String tripShortName;
private String internalPlanningCode;
private String tripHeadsign;
private String routeShortName;
@NotNull
private Direction direction = Direction.UNKNOWN;
private String blockId;
private FeedScopedId shapeId;
private int wheelchairAccessible = 0;
@Deprecated private int tripBikesAllowed = 0;
/**
* 0 = unknown / unspecified, 1 = bikes allowed, 2 = bikes NOT allowed
*/
private int bikesAllowed = 0;
/** Custom extension for KCM to specify a fare per-trip */
private String fareId;
/**
* Default alteration for a trip. // TODO Implement alterations for DSJ
*
* This is planned, by default (e.g. GTFS and if not set explicit).
*/
private TripAlteration alteration = TripAlteration.PLANNED;
public Trip(FeedScopedId id) {
super(id);
}
public Trip(Trip obj) {
this(obj.getId());
this.route = obj.route;
this.operator = obj.operator;
this.serviceId = obj.serviceId;
this.tripShortName = obj.tripShortName;
this.tripHeadsign = obj.tripHeadsign;
this.routeShortName = obj.routeShortName;
this.direction = obj.direction;
this.blockId = obj.blockId;
this.shapeId = obj.shapeId;
this.wheelchairAccessible = obj.wheelchairAccessible;
this.tripBikesAllowed = obj.tripBikesAllowed;
this.bikesAllowed = obj.bikesAllowed;
this.fareId = obj.fareId;
}
/**
* Operator running the trip. Returns operator of this trip, if it exist, or else the route operator.
*/
public Operator getOperator() {
return operator != null ? operator : route.getOperator();
}
/**
* This method return the operator associated with the trip. If the Trip have no Operator set {@code null} is
* returned. Note! this method do not consider the {@link Route} that the trip is part of.
* @see #getOperator()
*/
public Operator getTripOperator() {
return operator;
}
public void setTripOperator(Operator operator) {
this.operator = operator;
}
public Route getRoute() {
return route;
}
public void setRoute(Route route) {
this.route = route;
}
public FeedScopedId getServiceId() {
return serviceId;
}
public void setServiceId(FeedScopedId serviceId) {
this.serviceId = serviceId;
}
/**
* Public code or identifier for the journey. Equal to NeTEx PublicCode. GTFS and NeTEx have
* additional constraints on this fields that are not enforced in OTP.
*/
public String getTripShortName() {
return tripShortName;
}
public void setTripShortName(String tripShortName) {
this.tripShortName = tripShortName;
}
/**
* Return human friendly short info to identify the trip when mode, from/to stop and
* times are known. This method is meant for logging, and should not be exposed in any API.
*/
public String logInfo() {
if(hasValue(tripShortName)) { return tripShortName; }
if(hasValue(routeShortName)) { return routeShortName; }
if(route != null && hasValue(route.getName())) { return route.getName(); }
if(hasValue(tripHeadsign)) { return tripHeadsign; }
return getId().getId();
}
/**
* Internal code (non-public identifier) for the journey (e.g. train- or trip number from
* the planners' tool). This is kept to ensure compatibility with legacy planning systems.
* In NeTEx this maps to privateCode, there is no GTFS equivalent.
*/
public String getInternalPlanningCode() { return internalPlanningCode; }
public void setInternalPlanningCode(String internalPlanningCode) {
this.internalPlanningCode = internalPlanningCode;
}
public String getTripHeadsign() {
return tripHeadsign;
}
public void setTripHeadsign(String tripHeadsign) {
this.tripHeadsign = tripHeadsign;
}
public String getRouteShortName() {
return routeShortName;
}
public void setRouteShortName(String routeShortName) {
this.routeShortName = routeShortName;
}
// TODO Consider moving this to the TripPattern class once we have refactored the transit model
/**
* The direction for this Trip (and all other Trips in this TripPattern).
*/
@NotNull
public Direction getDirection() {
return direction;
}
public String getGtfsDirectionIdAsString(String unknownValue) {
return direction.equals(Direction.UNKNOWN)
? unknownValue
: Integer.toString(direction.gtfsCode);
}
public void setDirection(Direction direction) {
// Enforce non-null
this.direction = direction != null ? direction : Direction.UNKNOWN;
}
public String getBlockId() {
return blockId;
}
public void setBlockId(String blockId) {
this.blockId = blockId;
}
public FeedScopedId getShapeId() {
return shapeId;
}
public void setShapeId(FeedScopedId shapeId) {
this.shapeId = shapeId;
}
public void setWheelchairAccessible(int wheelchairAccessible) {
this.wheelchairAccessible = wheelchairAccessible;
}
public int getWheelchairAccessible() {
return wheelchairAccessible;
}
@Deprecated
public void setTripBikesAllowed(int tripBikesAllowed) {
this.tripBikesAllowed = tripBikesAllowed;
}
@Deprecated
public int getTripBikesAllowed() {
return tripBikesAllowed;
}
/**
* @return 0 = unknown / unspecified, 1 = bikes allowed, 2 = bikes NOT allowed
*/
public int getBikesAllowed() {
return bikesAllowed;
}
/**
* @param bikesAllowed 0 = unknown / unspecified, 1 = bikes allowed, 2 = bikes NOT allowed
*/
public void setBikesAllowed(int bikesAllowed) {
this.bikesAllowed = bikesAllowed;
}
public String toString() {
return "<Trip " + getId() + ">";
}
public String getFareId() {
return fareId;
}
public void setFareId(String fareId) {
this.fareId = fareId;
}
public TripAlteration getTripAlteration() {
return alteration;
}
public void setAlteration(TripAlteration tripAlteration) {
if (tripAlteration != null) {
this.alteration = tripAlteration;
}
}
private boolean hasValue(String text) {
return text != null && !text.isBlank();
}
}