MATSIM
TransitRouteImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * TransitRoute.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2009 by the members listed in the COPYING, *
8  * LICENSE and WARRANTY file. *
9  * email : info at matsim dot org *
10  * *
11  * *********************************************************************** *
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * See also COPYING, LICENSE and WARRANTY file *
18  * *
19  * *********************************************************************** */
20 
21 package org.matsim.pt.transitSchedule;
22 
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.TreeMap;
28 
29 import org.matsim.api.core.v01.Id;
37 
38 
44 public class TransitRouteImpl implements TransitRoute {
45 
46  private final Id<TransitRoute> routeId;
48  private final List<TransitRouteStop> stops = new ArrayList<>(8);
49  private String description = null;
50  private final Map<Id<Departure>, Departure> departures = new TreeMap<>();
51  private String transportMode;
52  private String direction;
53  private final Attributes attributes = new AttributesImpl();
54 
55  protected TransitRouteImpl(final Id<TransitRoute> id, final NetworkRoute route, final List<TransitRouteStop> stops, final String transportMode) {
56  this.routeId = id;
57  this.route = route;
58  this.stops.addAll(stops);
59  this.transportMode = transportMode;
60  }
61 
62  @Override
64  return this.routeId;
65  }
66 
67  @Override
68  public void setDescription(final String description) {
69  this.description = description;
70  }
71 
72  @Override
73  public String getDescription() {
74  return this.description;
75  }
76 
83  @Override
84  public void setTransportMode(final String mode) {
85  this.transportMode = mode;
86  }
87 
88  @Override
89  public String getTransportMode() {
90  return this.transportMode;
91  }
92 
93  @Override
94  public void addDeparture(final Departure departure) {
95  final Id<Departure> id = departure.getId();
96  if (this.departures.containsKey(id)) {
97  throw new IllegalArgumentException("There is already a departure with id " + id.toString() + " in transit route " + this.routeId);
98  }
99  this.departures.put(id, departure);
100  }
101 
102  @Override
103  public boolean removeDeparture(final Departure departure) {
104  return null != this.departures.remove(departure.getId());
105  }
106 
107  @Override
108  public Map<Id<Departure>, Departure> getDepartures() {
109  return Collections.unmodifiableMap(this.departures);
110  }
111 
112  @Override
114  return this.route;
115  }
116 
117  @Override
118  public void setRoute(final NetworkRoute route) {
119  this.route = route;
120  }
121 
122  @Override
123  public List<TransitRouteStop> getStops() {
124  return Collections.unmodifiableList(this.stops);
125  }
126 
127  @Override
129  for (TransitRouteStop trStop : this.stops) {
130  if (stop == trStop.getStopFacility()) {
131  return trStop;
132  }
133  }
134  return null;
135  }
136 
137  public String getDirection() {
138  return this.direction;
139  }
140 
141  public void setDirection(String direction) {
142  this.direction = direction;
143  }
144 
145  @Override
147  return this.attributes;
148  }
149 
150  @Override
151  public String toString() {
152  return "[TransitRouteImpl: route=" + this.routeId.toString() + ", #departures=" + this.departures.size() + "]";
153  }
154 
155 }
void setDescription(final String description)
final Map< Id< Departure >, Departure > departures
TransitRouteStop getStop(final TransitStopFacility stop)
TransitRouteImpl(final Id< TransitRoute > id, final NetworkRoute route, final List< TransitRouteStop > stops, final String transportMode)
boolean removeDeparture(final Departure departure)
Map< Id< Departure >, Departure > getDepartures()
void addDeparture(final Departure departure)