MATSIM
TransitScheduleImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * TransitSchedule.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.Collections;
24 import java.util.Map;
25 import java.util.TreeMap;
26 
27 import org.matsim.api.core.v01.Id;
36 
37 
45 public class TransitScheduleImpl implements TransitSchedule {
46 
47  private final Map<Id<TransitLine>, TransitLine> transitLines = new TreeMap<>();
48  private final Map<Id<TransitStopFacility>, TransitStopFacility> stopFacilities = new TreeMap<>();
50  private final Attributes attributes = new AttributesImpl();
51  private final MinimalTransferTimes minimalTransferTimes = new MinimalTransferTimesImpl();
52 
53  protected TransitScheduleImpl(final TransitScheduleFactory builder) {
54  this.factory = builder;
55  }
56 
57  @Override
58  public void addTransitLine(final TransitLine line) {
59  final Id<TransitLine> id = line.getId();
60  if (this.transitLines.containsKey(id)) {
61  throw new IllegalArgumentException("There is already a transit line with id " + id.toString());
62  }
63  this.transitLines.put(id, line);
64  }
65 
66  @Override
67  public boolean removeTransitLine(TransitLine line) {
68  TransitLine oldLine = this.transitLines.remove(line.getId());
69  if (oldLine == null) {
70  return false;
71  }
72  if (oldLine != line) {
73  this.transitLines.put(oldLine.getId(), oldLine);
74  return false;
75  }
76  return true;
77  }
78 
79  @Override
80  public void addStopFacility(final TransitStopFacility stop) {
81  final Id<TransitStopFacility> id = stop.getId();
82  if (this.stopFacilities.containsKey(id)) {
83  throw new IllegalArgumentException("There is already a stop facility with id " + id.toString());
84  }
85  this.stopFacilities.put(id, stop);
86  }
87 
88  @Override
89  public Map<Id<TransitLine>, TransitLine> getTransitLines() {
90  return Collections.unmodifiableMap(this.transitLines);
91  }
92 
93  @Override
94  public Map<Id<TransitStopFacility>, TransitStopFacility> getFacilities() {
95  return Collections.unmodifiableMap(this.stopFacilities);
96  }
97 
98  @Override
99  public boolean removeStopFacility(TransitStopFacility stop) {
100  TransitStopFacility oldStop = this.stopFacilities.remove(stop.getId());
101  if (oldStop == null) {
102  return false;
103  }
104  if (oldStop != stop) {
105  this.stopFacilities.put(oldStop.getId(), oldStop);
106  return false;
107  }
108  return true;
109  }
110 
111  @Override
113  return this.factory;
114  }
115 
116  @Override
119  }
120 
121  @Override
124  }
125 
126  @Override
128  return this.attributes;
129  }
130 
131  @Override
133  return this.minimalTransferTimes;
134  }
135 }
boolean removeStopFacility(TransitStopFacility stop)
TransitScheduleImpl(final TransitScheduleFactory builder)
Map< Id< TransitStopFacility >, TransitStopFacility > getFacilities()
final Map< Id< TransitStopFacility >, TransitStopFacility > stopFacilities
final Map< Id< TransitLine >, TransitLine > transitLines
Map< Id< TransitLine >, TransitLine > getTransitLines()
void addStopFacility(final TransitStopFacility stop)