MATSIM
ActivityImpl.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * Act.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 2007, 2008 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.core.population;
22 
23 import org.matsim.api.core.v01.Coord;
24 import org.matsim.api.core.v01.Id;
28 import org.matsim.core.utils.misc.Time;
32 
41 /* package */ final class ActivityImpl implements Activity {
42  // Assume this as input to iterations. Cases:
43  // Case (0): comes with coord and linkId. No problem.
44  // Case (1): comes with linkId but w/o coord. Coord is (presumably) set in prepareForIterations.
45  // Case (2): comes with coord but w/o linkId. LinkId is (presumably) set in prepareForIterations.
46 
47  // Case (X): facilityId inconsistent with linkId, coord. Idea: mobsim takes the facilityId and (a) checks the other
48  // attribs or (b) ignores them.
49 
50  private static final double UNDEFINED_TIME = Double.NEGATIVE_INFINITY;
51  private double endTime = UNDEFINED_TIME;
52 
56  private double startTime = UNDEFINED_TIME;
57 
58  private double dur = UNDEFINED_TIME;
59 
60  private String type;
61  private Coord coord = null;
62  private Id<Link> linkId = null;
63  private Id<ActivityFacility> facilityId = null;
64 
65  private Attributes attributes = null;
66 
67  /*package*/ ActivityImpl(final String type) {
68  this.type = type.intern();
69  }
70 
71  private static OptionalTime asOptionalTime(double seconds) {
72  return seconds == UNDEFINED_TIME ? OptionalTime.undefined() : OptionalTime.defined(seconds);
73  }
74 
75  @Override
76  public OptionalTime getEndTime() {
77  return asOptionalTime(this.endTime);
78  }
79 
80  @Override
81  public void setEndTime(final double endTime) {
82  OptionalTime.assertDefined(endTime);
83  this.endTime = endTime;
84  }
85 
86  @Override
87  public void setEndTimeUndefined() {
88  this.endTime = UNDEFINED_TIME;
89  }
90 
94  @Override
95  public OptionalTime getStartTime() {
96  return asOptionalTime(this.startTime);
97  }
98 
102  @Override
103  public void setStartTime(final double startTime) {
104  OptionalTime.assertDefined(startTime);
105  this.startTime = startTime;
106  }
107 
108  public void setStartTimeUndefined() {
109  this.startTime = UNDEFINED_TIME;
110  }
111 
112  @Override
113  public String getType() {
114  return this.type;
115  }
116 
117  @Override
118  public void setType(final String type) {
119  this.type = type.intern();
120  }
121 
122  @Override
123  public Coord getCoord() {
124  return this.coord;
125  }
126  @Override
127  public void setCoord(final Coord coord) {
128 // testForLocked();
129  // I currently think that rather than enforcing data consistency we should just walk them from coordinate to link. kai, dec'15
130  this.coord = coord;
131  }
132  @Override
133  public Id<Link> getLinkId() {
134  return this.linkId;
135  }
136 
137  @Override
138  public Id<ActivityFacility> getFacilityId() {
139  return this.facilityId;
140  }
141 
142  @Override
143  public void setFacilityId(final Id<ActivityFacility> facilityId) {
144 // testForLocked();
145  this.facilityId = facilityId;
146  }
147 
148  @Override
149  public void setLinkId(final Id<Link> linkId) {
150 // testForLocked();
151  // I currently think that rather than enforcing data consistency we should just walk them from coordinate to link. kai, dec'15
152  this.linkId = linkId;
153  }
154 
155  @Override
156  public String toString() {
157  return "act [type="
158  + this.getType()
159  + "]"
160  + "[coord="
161  + this.getCoord()
162  + "]"
163  + "[linkId="
164  + this.linkId
165  + "]"
166  + "[startTime="
167  + Time.writeTime(getStartTime())
168  + "]"
169  + "[endTime="
170  + Time.writeTime(this.endTime)
171  + "]"
172  + "[duration="
173  + Time.writeTime(getMaximumDuration())
174  + "]"
175  + "[facilityId="
176  + this.facilityId + "]" ;
177  }
178 
179  @Override
180  public OptionalTime getMaximumDuration() {
181  return asOptionalTime(this.dur);
182  }
183 
184  @Override
185  public void setMaximumDuration(final double dur) {
187  this.dur = dur;
188  }
189 
190  @Override
191  public void setMaximumDurationUndefined() {
192  this.dur = UNDEFINED_TIME;
193  }
194 
195  @Override
196  public Attributes getAttributes() {
197  if (this.attributes != null) {
198  return this.attributes;
199  }
200  return new LazyAllocationAttributes(attributes -> this.attributes = attributes, () -> this.attributes);
201  }
202 
203 // private boolean locked = false ;
204 // public final void setLocked() {
205 // this.locked = true ;
206 // }
207 // private final void testForLocked() {
208 // if ( this.locked ) {
209 // throw new RuntimeException("too late to do this") ;
210 // }
211 // }
212 }
static final String writeTime(final double seconds, final String timeformat)
Definition: Time.java:80
static OptionalTime defined(double seconds)
static void assertDefined(double seconds)