MATSIM
ActivityStartEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * ActStartEvent.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.api.core.v01.events;
22 
24 import org.matsim.api.core.v01.Coord;
25 import org.matsim.api.core.v01.Id;
29 
30 import java.util.Map;
31 
33 
35 
36  public static final String EVENT_TYPE = "actstart";
37  public static final String ATTRIBUTE_ACTTYPE = "actType";
38 
39 
40  private final Id<Person> personId;
41  private Coord coord;
42  private final Id<Link> linkId;
44  private final String acttype;
45 
46  /*
47  Possible transition path to "coordinates in event":
48  - invalidate previous constructor so that we see where we have problems.
49  - be minimalistic in repairing (e.g. only in matsim core). As a tendency, when the event constructor already contains null args (e.g. for facility),
50  then we can put null for coord as well.
51  - re-instantiate previous constructor. I find this better than null because one can still set the constructor to deprecated and get compile time
52  warnings. kai, dec'19
53  */
54 
55 // public ActivityStartEvent( final double time, final Id<Person> agentId, final Activity activity ){
56 // this( time, agentId, activity.getLinkId(), activity ) ;
57 // }
58 // public ActivityStartEvent( final double time, final Id<Person> agentId, final Id<Link> linkId, final Activity activity ) {
59 // this( time, agentId, linkId, activity.getFacilityId(), activity.getType(), activity.getCoord() ) ;
60 // }
61 
65  @Deprecated // add Coord as argument
66  public ActivityStartEvent( final double time, final Id<Person> agentId, final Id<Link> linkId, final Id<ActivityFacility> facilityId, final String acttype ){
67  this( time, agentId, linkId, facilityId, acttype, null);
68  }
69  // this is the new constructor:
70  public ActivityStartEvent( final double time, final Id<Person> agentId, final Id<Link> linkId,
71  final Id<ActivityFacility> facilityId, final String acttype, final Coord coord ) {
72  super(time);
73  this.linkId = linkId;
74  this.facilityId = facilityId;
75  this.acttype = acttype == null ? "" : acttype;
76  this.personId = agentId;
77  this.coord = coord;
78  }
79 
80  @Override public String getEventType() {
81  return EVENT_TYPE;
82  }
83 
84  public String getActType() {
85  return this.acttype;
86  }
87  @Override public Id<Link> getLinkId() {
88  return this.linkId;
89  }
90  @Override public Id<ActivityFacility> getFacilityId() {
91  return this.facilityId;
92  }
93  @Override public Id<Person> getPersonId() {
94  return this.personId;
95  }
96 
97  @Override
98  public Map<String, String> getAttributes() {
99  Map<String, String> attr = super.getAttributes();
100  // personId is automatic in superclass
101  // coord is automatic in superclass
102  // linkId is automatic in superclass
103  // facilityId is automatic in superclass
104  attr.put(ATTRIBUTE_ACTTYPE, this.acttype);
105  return attr;
106  }
107  @Override public Coord getCoord(){
108  return coord;
109  }
110  public void setCoord( Coord coord ) {
111  // yy this is to retrofit the coordinate into existing events that don't have it. :-( kai, mar'20
112  this.coord = coord;
113  }
114 
115  @Override
116  public void writeAsXML(StringBuilder out) {
117  // Writes common attributes
118  writeXMLStart(out);
119  writeEncodedAttributeKeyValue(out, ATTRIBUTE_ACTTYPE, this.acttype);
120  writeXMLEnd(out);
121  }
122 }
final void writeXMLEnd(StringBuilder out)
Definition: Event.java:151
ActivityStartEvent(final double time, final Id< Person > agentId, final Id< Link > linkId, final Id< ActivityFacility > facilityId, final String acttype)
ActivityStartEvent(final double time, final Id< Person > agentId, final Id< Link > linkId, final Id< ActivityFacility > facilityId, final String acttype, final Coord coord)
final void writeXMLStart(StringBuilder out)
Definition: Event.java:116
static StringBuilder writeEncodedAttributeKeyValue(StringBuilder out, String key, String value)
Definition: XmlUtils.java:117