MATSIM
PersonScoreEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * *********************************************************************** *
4  * *
5  * copyright : (C) 2020 by the members listed in the COPYING, *
6  * LICENSE and WARRANTY file. *
7  * email : info at matsim dot org *
8  * *
9  * *********************************************************************** *
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * See also COPYING, LICENSE and WARRANTY file *
16  * *
17  * *********************************************************************** */
18 
19 package org.matsim.api.core.v01.events;
20 
21 import org.matsim.api.core.v01.Id;
24 
25 import java.util.Map;
26 
33 public class PersonScoreEvent extends Event implements HasPersonId {
34 
35  public static final String EVENT_TYPE = "personScore";
36 
37  public static final String ATTRIBUTE_AMOUNT = "amount";
38  public static final String ATTRIBUTE_KIND = "kind";
39 
40  private final Id<Person> personId;
41  private final double amount;
42  private final String kind;
43 
44  public PersonScoreEvent(double time, Id<Person> personId, double amount, String kind) {
45  super(time);
46  this.personId = personId;
47  this.amount = amount;
48  this.kind = kind;
49  }
50 
51  @Override
53  return this.personId;
54  }
55 
56  public double getAmount() {
57  return this.amount;
58  }
59 
60  public String getKind() {
61  return this.kind;
62  }
63 
64  @Override
65  public String getEventType() {
66  return EVENT_TYPE;
67  }
68 
69  @Override
70  public Map<String, String> getAttributes() {
71  Map<String, String> attr = super.getAttributes();
72  // personId is added by super-class
73  attr.put(ATTRIBUTE_AMOUNT, Double.toString(this.amount));
74  if (this.kind != null) {
75  attr.put(ATTRIBUTE_KIND, this.kind);
76  }
77  return attr;
78  }
79 
80  @Override
81  public void writeAsXML(StringBuilder out) {
82  writeXMLStart(out);
83  out.append("amount=\"").append(this.amount).append("\" ");
84  if (this.kind != null) {
85  XmlUtils.writeEncodedAttributeKeyValue(out, ATTRIBUTE_KIND, this.kind);
86  }
87  writeXMLEnd(out);
88  }
89 }
final void writeXMLEnd(StringBuilder out)
Definition: Event.java:151
PersonScoreEvent(double time, Id< Person > personId, double amount, String kind)
final void writeXMLStart(StringBuilder out)
Definition: Event.java:116
static StringBuilder writeEncodedAttributeKeyValue(StringBuilder out, String key, String value)
Definition: XmlUtils.java:117