MATSIM
PersonStuckEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * AgentStuckEvent.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 
23 import java.util.Map;
24 
25 import org.matsim.api.core.v01.Id;
29 
30 public class PersonStuckEvent extends Event implements HasPersonId, HasLinkId {
31 
32  public static final String EVENT_TYPE = "stuckAndAbort";
33 
34  public static final String ATTRIBUTE_LINK = "link";
35  public static final String ATTRIBUTE_LEGMODE = "legMode";
36  public static final String ATTRIBUTE_PERSON = "person";
37  public static final String ATTRIBUTE_REASON = "reason";
38 
39  private final Id<Person> personId;
40  private final Id<Link> linkId;
41  private final String legMode;
42  private final String reason;
43 
44  public PersonStuckEvent(final double time, final Id<Person> agentId, final Id<Link> linkId, final String legMode, String reason) {
45  super(time);
46  this.personId = agentId;
47  this.linkId = linkId;
48  this.legMode = legMode;
49  this.reason = reason;
50  }
51 
52  public PersonStuckEvent(final double time, final Id<Person> agentId, final Id<Link> linkId, final String legMode) {
53  this(time, agentId, linkId, legMode, null);
54  }
55 
57  return this.personId;
58  }
59 
60  public Id<Link> getLinkId() {
61  return this.linkId;
62  }
63 
64  public String getLegMode() {
65  return this.legMode;
66  }
67 
68  public String getReason() {
69  return this.reason;
70  }
71 
72  @Override
73  public String getEventType() {
74  return EVENT_TYPE;
75  }
76 
77  @Override
78  public Map<String, String> getAttributes() {
79  Map<String, String> attr = super.getAttributes();
80  // personId, linkId handled by superclass
81  if (this.legMode != null) {
82  attr.put(ATTRIBUTE_LEGMODE, this.legMode);
83  }
84  if (this.reason != null) {
85  attr.put(ATTRIBUTE_REASON, this.legMode);
86  }
87  return attr;
88  }
89 
90  @Override
91  public void writeAsXML(StringBuilder out) {
92  // Writes all common attributes
93  writeXMLStart(out);
94 
95  if (this.legMode != null) {
96  XmlUtils.writeEncodedAttributeKeyValue(out, ATTRIBUTE_LEGMODE, this.legMode);
97  }
98 
99  if (this.reason != null) {
100  XmlUtils.writeEncodedAttributeKeyValue(out, ATTRIBUTE_REASON, this.reason);
101  }
102 
103  writeXMLEnd(out);
104  }
105 }
final void writeXMLEnd(StringBuilder out)
Definition: Event.java:151
final void writeXMLStart(StringBuilder out)
Definition: Event.java:116
PersonStuckEvent(final double time, final Id< Person > agentId, final Id< Link > linkId, final String legMode, String reason)
PersonStuckEvent(final double time, final Id< Person > agentId, final Id< Link > linkId, final String legMode)
static StringBuilder writeEncodedAttributeKeyValue(StringBuilder out, String key, String value)
Definition: XmlUtils.java:117