MATSIM
ActivityFacilityImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * Facility.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007 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.facilities;
22 
23 import java.util.Map;
24 import java.util.TreeMap;
25 
26 import org.matsim.api.core.v01.Coord;
28 import org.matsim.api.core.v01.Id;
36 
41  // After some thinking, we think that this design is ok:
42  // * all methods are final (reduce maintenance for upstream maintainers)
43  // * the class itself is not final
44  // * the constructor is protected
45  // * derived classes can thus extend to the attributes
46 
47  // yyyyyy I have to say that I am at this point not so happy. Better make it final, make it package-protected, make
48  // all functionality accessible by interface or from static methods, and then let external users use delegation.
49  // People need to get un-used to casting things into the impl to get hold of "special" functionality. kai, jul'16
50 
52 
53  private final Map<String, ActivityOption> activities = new TreeMap<>();
54 
55  private String desc = null;
56 
57  private Coord coord;
58 
60 
61  private Id<Link> linkId;
62 
63  private boolean locked = false ;
64 
65  private final Attributes attributes = new AttributesImpl();
66 
73  protected ActivityFacilityImpl(final Id<ActivityFacility> id, final Coord center, final Id<Link> linkId) {
74  this.id = id;
75  this.coord = center;
76  this.linkId = linkId;
77  }
78 
79  public final double calcDistance(Coord otherCoord) {
80  return CoordUtils.calcEuclideanDistance(this.coord, otherCoord);
81  }
82 
83  public final ActivityOptionImpl createAndAddActivityOption(final String type) {
84  String type2 = type.intern();
87  return a;
88  }
89 
90  @Override
91  public final void addActivityOption(ActivityOption option) {
92  String type = option.getType() ;
93  if (this.activities.containsKey(type)) {
94  throw new RuntimeException(this + "[type=" + type + " already exists]");
95  }
96  this.activities.put(type, option);
97  }
98  @Override
99  public final void setCoord(Coord newCoord) {
100  testForLocked() ;
101  this.coord = newCoord;
102  }
103 
104  public final void setDesc(String desc) {
105  if (desc == null) { this.desc = null; }
106  else { this.desc = desc.intern(); }
107  }
108 
109  public final String getDesc() {
110  return this.desc;
111  }
112 
113  @Override
114  public final Map<String, ActivityOption> getActivityOptions() {
115  return this.activities;
116  }
117 
118  @Override
119  public final Id<Link> getLinkId() {
120  return this.linkId;
121  }
122 
123  public final void setLinkId(Id<Link> linkId) {
124  this.linkId = linkId;
125  }
126 
127  @Override
128  public final String toString() {
129  return "[" + super.toString() +
130  " ID=" + this.id +
131  "| linkID=" + this.linkId +
132  "| nof_activities=" + this.activities.size() +
133  "]";
134  }
135 
136  @Override
137  public final Coord getCoord() {
138  return this.coord;
139  }
140 
141  @Override
142  public final Id<ActivityFacility> getId() {
143  return this.id;
144  }
145 
146  @Override
147  public final Map<String, Object> getCustomAttributes() {
148  if (this.customizableDelegate == null) {
149  this.customizableDelegate = CustomizableUtils.createCustomizable();
150  }
151  return this.customizableDelegate.getCustomAttributes();
152  }
153 
154  @Override
155  public void setLocked() {
156  this.locked = true ;
157  }
158 
159  private void testForLocked() {
160  if ( this.locked ) {
161  throw new RuntimeException("too late to do this") ;
162  }
163  }
164 
165  @Override
167  return this.attributes;
168  }
169 }
final Map< String, Object > getCustomAttributes()
static double calcEuclideanDistance(Coord coord, Coord other)
Map< String, Object > getCustomAttributes()
final void addActivityOption(ActivityOption option)
final Map< String, ActivityOption > activities
final Map< String, ActivityOption > getActivityOptions()
final ActivityOptionImpl createAndAddActivityOption(final String type)
ActivityFacilityImpl(final Id< ActivityFacility > id, final Coord center, final Id< Link > linkId)