MATSIM
PersonMoneyEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * AgentMoneyEvent.java
4  * *
5  * *********************************************************************** *
6  * *
7  * copyright : (C) 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 org.matsim.api.core.v01.Id;
25 
26 import java.util.Map;
27 
29 
38 public final class PersonMoneyEvent extends Event implements HasPersonId {
39 
40  public static final String EVENT_TYPE = "personMoney";
41 
42  public static final String ATTRIBUTE_AMOUNT = "amount";
43  public static final String ATTRIBUTE_PURPOSE = "purpose";
44  public static final String ATTRIBUTE_TRANSACTION_PARTNER = "transactionPartner";
45  public static final String ATTRIBUTE_REFERENCE = "reference";
46 
47  private final Id<Person> personId;
48  private final double amount;
49  private final String purpose;
50  private final String transactionPartner;
51  private final String reference;
52 
71  public PersonMoneyEvent(final double time, final Id<Person> agentId, final double amount, final String purpose,
72  final String transactionPartner, final String reference) {
73  super(time);
74  this.personId = agentId;
75  this.amount = amount;
76  this.purpose = purpose;
77  this.transactionPartner = transactionPartner;
78  this.reference = reference;
79  }
83  @Deprecated // add "purpose" and "transactionPartner" and "reference"
84  public PersonMoneyEvent(final double time, final Id<Person> agentId, final double amount) {
85  this( time, agentId, amount, null, null, null);
86  }
87 
91  @Deprecated // add "reference"
92  public PersonMoneyEvent(final double time, final Id<Person> agentId, final double amount, final String purpose,
93  final String transactionPartner) {
94  this(time, agentId, amount, purpose, transactionPartner, null);
95  }
96 
97  @Override
99  return this.personId;
100  }
101 
102  public double getAmount() {
103  return this.amount;
104  }
105 
106  public String getPurpose() {
107  return this.purpose;
108  }
109 
110  public String getTransactionPartner() {
111  return this.transactionPartner;
112  }
113 
114  public String getReference() {
115  return this.reference;
116  }
117 
118  @Override
119  public String getEventType() {
120  return EVENT_TYPE;
121  }
122 
123  @Override
124  public Map<String, String> getAttributes() {
125  Map<String, String> attr = super.getAttributes();
126  // personId is treated in upstream
127  attr.put(ATTRIBUTE_AMOUNT, Double.toString(this.amount));
128  if (this.purpose != null) {
129  attr.put(ATTRIBUTE_PURPOSE, this.purpose);
130  }
131  if (this.transactionPartner != null) {
132  attr.put(ATTRIBUTE_TRANSACTION_PARTNER, this.transactionPartner);
133  }
134  if (this.reference != null) {
135  attr.put(ATTRIBUTE_REFERENCE, this.reference);
136  }
137  return attr;
138  }
139 
140  @Override
141  public void writeAsXML(StringBuilder out) {
142  // Writes all common attributes
143  writeXMLStart(out);
144 
145  out.append("amount=\"").append(this.amount).append("\" ");
146  if (this.purpose != null) {
147  writeEncodedAttributeKeyValue(out, ATTRIBUTE_PURPOSE, this.purpose);
148  }
149  if (this.transactionPartner != null) {
150  writeEncodedAttributeKeyValue(out, ATTRIBUTE_TRANSACTION_PARTNER, this.transactionPartner);
151  }
152  if (this.reference != null) {
153  writeEncodedAttributeKeyValue(out, ATTRIBUTE_REFERENCE, this.reference);
154  }
155 
156  writeXMLEnd(out);
157  }
158 }
PersonMoneyEvent(final double time, final Id< Person > agentId, final double amount)
final void writeXMLEnd(StringBuilder out)
Definition: Event.java:151
PersonMoneyEvent(final double time, final Id< Person > agentId, final double amount, final String purpose, final String transactionPartner)
final void writeXMLStart(StringBuilder out)
Definition: Event.java:116
PersonMoneyEvent(final double time, final Id< Person > agentId, final double amount, final String purpose, final String transactionPartner, final String reference)
static StringBuilder writeEncodedAttributeKeyValue(StringBuilder out, String key, String value)
Definition: XmlUtils.java:117