MATSIM
TransitLineImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * TransitLine.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.LinkedHashMap;
25 import java.util.Map;
26 
27 import org.matsim.api.core.v01.Id;
32 
33 
39 public class TransitLineImpl implements TransitLine {
40 
41  private final Id<TransitLine> lineId;
42  private String name = null;
43  private final Map<Id<TransitRoute>, TransitRoute> transitRoutes = new LinkedHashMap<>(5);
44  private final Attributes attributes = new AttributesImpl();
45 
46  protected TransitLineImpl(final Id<TransitLine> id) {
47  this.lineId = id;
48  }
49 
50  @Override
52  return this.lineId;
53  }
54 
55  @Override
56  public String getName() {
57  return this.name;
58  }
59 
60  @Override
61  public void setName(String name) {
62  this.name = name;
63  }
64 
65  @Override
66  public void addRoute(final TransitRoute transitRoute) {
67  final Id<TransitRoute> id = transitRoute.getId();
68  if (this.transitRoutes.containsKey(id)) {
69  throw new IllegalArgumentException("There is already a transit route with id " + id.toString() + " with line " + this.lineId);
70  }
71  this.transitRoutes.put(id, transitRoute);
72  }
73 
74  @Override
75  public Map<Id<TransitRoute>, TransitRoute> getRoutes() {
76  return Collections.unmodifiableMap(this.transitRoutes);
77  }
78 
79  @Override
80  public boolean removeRoute(final TransitRoute route) {
81  return null != this.transitRoutes.remove(route.getId());
82  }
83 
84  @Override
86  return this.attributes;
87  }
88 
89  @Override
90  public String toString() {
91  return "[TransitLineImpl: line=" + this.lineId.toString() + ", #routes=" + this.transitRoutes.size() + "]";
92  }
93 
94 }
final Map< Id< TransitRoute >, TransitRoute > transitRoutes
Map< Id< TransitRoute >, TransitRoute > getRoutes()
boolean removeRoute(final TransitRoute route)
void addRoute(final TransitRoute transitRoute)