MATSIM
LinkLeaveEvent.java
Go to the documentation of this file.
1 /* *********************************************************************** *
2  * project: org.matsim.*
3  * LinkLeaveEvent.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 org.matsim.api.core.v01.Id;
26 import org.matsim.vehicles.Vehicle;
27 
28 import java.util.Map;
29 
30 public class LinkLeaveEvent extends Event implements HasLinkId, HasVehicleId {
31 
32  public static final String EVENT_TYPE = "left link";
33  public static final String ATTRIBUTE_LINK = "link";
34 
35  private final Id<Link> linkId;
36  private final Id<Vehicle> vehicleId;
37 
38  final static String missingDriverIdMessage = "driver (or person) ID does no longer exist in LinkEnter/LeaveEvent; use vehicle ID instead. "
39  + "See Vehicle2DriverEventHandler for an approach to reconstruct the driver ID and/or EventsConverterXML to convert your old event file.";
40 
41  public LinkLeaveEvent(final double time, final Id<Vehicle> vehicleId, final Id<Link> linkId) {
42  super(time);
43  this.linkId = linkId;
44  if ( vehicleId==null ) {
45  throw new RuntimeException( LinkEnterEvent.missingVehicleIdMessage ) ;
46  }
47  this.vehicleId = vehicleId;
48  }
49 
50  @Override
51  public String getEventType() {
52  return EVENT_TYPE;
53  }
54 
59  @Deprecated
61  throw new RuntimeException(missingDriverIdMessage ) ;
62  }
63 
64  @Override
65  public Id<Link> getLinkId() {
66  return this.linkId;
67  }
68 
70  return vehicleId;
71  }
72 
73  @Override
74  public Map<String, String> getAttributes() {
75  Map<String, String> atts = super.getAttributes();
76  // linkId, vehicleId handled by superclass
77  return atts;
78  }
79 
80  @Override
81  public void writeAsXML(StringBuilder out) {
82  // Writes all common attributes
83  writeXMLStart(out);
84  writeXMLEnd(out);
85  }
86 }
final void writeXMLEnd(StringBuilder out)
Definition: Event.java:151
final void writeXMLStart(StringBuilder out)
Definition: Event.java:116