MATSIM
InteractionActivity.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 
37 /*package*/ final class InteractionActivity implements Activity {
38 
39  private static final Attributes EMPTY_ATTRIBUTES = new LazyAllocationAttributes(attributes -> {
40  throw new RuntimeException("interaction activities cannot have attributes.");
41  }, () -> null);
42 
43  private String type;
44  private Coord coord = null;
45  private Id<Link> linkId = null;
46  private Id<ActivityFacility> facilityId = null;
47 
48  /*package*/ InteractionActivity(final String type) {
49  this.type = type.intern();
50  }
51 
52  @Override
53  public OptionalTime getEndTime() {
54  return OptionalTime.undefined();
55  }
56 
57  @Override
58  public void setEndTime(final double endTime) {
59  throw new UnsupportedOperationException("Setting duration is not supported for InteractionActivity.");
60  }
61 
62  @Override
63  public void setEndTimeUndefined() {
64  // It is already undefined, i.e. do nothing.
65  }
66 
67  @Override
68  public OptionalTime getStartTime() {
69  return OptionalTime.undefined();
70  }
71 
72  @Override
73  public void setStartTime(final double startTime) {
74  throw new UnsupportedOperationException("Setting start time is not supported for InteractionActivity.");
75  }
76 
77  @Override
78  public void setStartTimeUndefined() {
79  // It is already undefined, i.e. do nothing.
80  }
81 
82  @Override
83  public OptionalTime getMaximumDuration() {
84  return OptionalTime.zeroSeconds();
85  }
86 
87  @Override
88  public void setMaximumDuration(final double dur) {
89  // For compatibility reasons: allow setting duration to 0 which is the default value anyway.
90  if (dur != 0) throw new UnsupportedOperationException("Setting duration is not supported for InteractionActivity.");
91  }
92 
93  @Override
94  public void setMaximumDurationUndefined() {
95  throw new UnsupportedOperationException("Setting duration to undefined is not supported for InteractionActivity.");
96  }
97 
98  @Override
99  public String getType() {
100  return this.type;
101  }
102 
103  @Override
104  public void setType(final String type) {
105  this.type = type.intern();
106  }
107 
108  @Override
109  public Coord getCoord() {
110  return this.coord;
111  }
112 
113  @Override
114  public void setCoord(final Coord coord) {
115  this.coord = coord;
116  }
117 
118  @Override
119  public Id<Link> getLinkId() {
120  return this.linkId;
121  }
122 
123  @Override
124  public Id<ActivityFacility> getFacilityId() {
125  return this.facilityId;
126  }
127 
128  @Override
129  public void setFacilityId(final Id<ActivityFacility> facilityId) {
130  this.facilityId = facilityId;
131  }
132 
133  @Override
134  public void setLinkId(final Id<Link> linkId) {
135  this.linkId = linkId;
136  }
137 
138  @Override
139  public Attributes getAttributes() {
140  return EMPTY_ATTRIBUTES;
141 }
142 
143  @Override
144  public String toString() {
145  return "act [type="
146  + this.getType()
147  + "]"
148  + "[coord="
149  + this.getCoord()
150  + "]"
151  + "[linkId="
152  + this.linkId
153  + "]"
154  + "[startTime="
155  + Time.writeTime(getStartTime())
156  + "]"
157  + "[endTime="
158  + Time.writeTime(getEndTime())
159  + "]"
160  + "[duration="
161  + Time.writeTime(getMaximumDuration())
162  + "]"
163  + "[facilityId="
164  + this.facilityId + "]" ;
165  }
166 }