From 47d5d307895ab04250b779d6e6e8a2fbffa8b6f9 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Wed, 27 Dec 2023 21:07:38 +0100 Subject: [PATCH] core: simplify getAttributes() in core events --- .../api/core/v01/events/LinkEnterEvent.java | 17 +++++++------ .../api/core/v01/events/LinkLeaveEvent.java | 13 +++++----- .../core/v01/events/PersonArrivalEvent.java | 15 ++++++------ .../core/v01/events/PersonDepartureEvent.java | 15 ++++++------ .../v01/events/PersonEntersVehicleEvent.java | 15 ++++++------ .../v01/events/PersonLeavesVehicleEvent.java | 13 +++++----- .../api/core/v01/events/PersonStuckEvent.java | 17 ++++++------- .../core/v01/events/VehicleAbortsEvent.java | 19 +++++++-------- .../v01/events/VehicleEntersTrafficEvent.java | 24 ++++++++----------- .../v01/events/VehicleLeavesTrafficEvent.java | 21 +++++++--------- 10 files changed, 75 insertions(+), 94 deletions(-) diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/LinkEnterEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/LinkEnterEvent.java index 2f6ec7165f3..63250efa333 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/LinkEnterEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/LinkEnterEvent.java @@ -27,7 +27,7 @@ import java.util.Map; -public class LinkEnterEvent extends Event implements HasLinkId, HasVehicleId{ +public class LinkEnterEvent extends Event implements HasLinkId, HasVehicleId { public static final String EVENT_TYPE = "entered link"; @@ -49,29 +49,28 @@ public LinkEnterEvent(final double time, final Id vehicleId, final Id getDriverId() { throw new RuntimeException( LinkLeaveEvent.missingDriverIdMessage ) ; - } + } @Override public Id getLinkId() { return this.linkId; } - + public Id getVehicleId() { return vehicleId; } @Override public Map getAttributes() { - Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); - attr.put(ATTRIBUTE_LINK, this.linkId.toString()); - return attr; + Map atts = super.getAttributes(); + // linkId, vehicleId handled by superclass + return atts; } } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/LinkLeaveEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/LinkLeaveEvent.java index a2524206ece..06018363204 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/LinkLeaveEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/LinkLeaveEvent.java @@ -27,7 +27,7 @@ import java.util.Map; -public class LinkLeaveEvent extends Event implements HasLinkId, HasVehicleId{ +public class LinkLeaveEvent extends Event implements HasLinkId, HasVehicleId { public static final String EVENT_TYPE = "left link"; public static final String ATTRIBUTE_LINK = "link"; @@ -53,7 +53,7 @@ public String getEventType() { } /** - * Please use getVehicleId() instead. + * Please use getVehicleId() instead. * Vehicle-driver relations can be made by Wait2Link (now: VehicleEntersTraffic) and VehicleLeavesTraffic Events. */ @Deprecated @@ -69,12 +69,11 @@ public Id getLinkId() { public Id getVehicleId() { return vehicleId; } - + @Override public Map getAttributes() { - Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); - attr.put(ATTRIBUTE_LINK, this.linkId.toString()); - return attr; + Map atts = super.getAttributes(); + // linkId, vehicleId handled by superclass + return atts; } } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonArrivalEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonArrivalEvent.java index a6c49d62198..6e947aaff11 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonArrivalEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonArrivalEvent.java @@ -26,10 +26,10 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; -public class PersonArrivalEvent extends Event implements HasPersonId { +public class PersonArrivalEvent extends Event implements HasPersonId, HasLinkId { public static final String EVENT_TYPE = "arrival"; - + public static final String ATTRIBUTE_PERSON = "person"; public static final String ATTRIBUTE_LINK = "link"; public static final String ATTRIBUTE_LEGMODE = "legMode"; @@ -45,7 +45,7 @@ public PersonArrivalEvent(final double time, final Id agentId, final Id< this.legMode = legMode; this.personId = agentId; } - + public Id getPersonId() { return this.personId; } @@ -53,20 +53,19 @@ public Id getPersonId() { public Id getLinkId() { return this.linkId; } - + public String getLegMode() { return this.legMode; } - + public String getEventType() { return EVENT_TYPE; } - + @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_PERSON, this.personId.toString()); - attr.put(ATTRIBUTE_LINK, (this.linkId == null ? null : this.linkId.toString())); + // linkId, personId handled by superclass if (this.legMode != null) { attr.put(ATTRIBUTE_LEGMODE, this.legMode); } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonDepartureEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonDepartureEvent.java index 0dc5555778f..425d8ad4e78 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonDepartureEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonDepartureEvent.java @@ -26,7 +26,7 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; -public class PersonDepartureEvent extends Event implements HasPersonId { +public class PersonDepartureEvent extends Event implements HasPersonId, HasLinkId { public static final String EVENT_TYPE = "departure"; @@ -47,24 +47,24 @@ public PersonDepartureEvent(final double time, final Id agentId, final I this.personId = agentId; this.routingMode = routingMode; } - + @Override public Id getPersonId() { return this.personId; } - + public Id getLinkId() { return this.linkId; } - + public String getLegMode() { return this.legMode; } - + public String getRoutingMode() { return routingMode; } - + @Override public String getEventType() { return EVENT_TYPE; @@ -73,8 +73,7 @@ public String getEventType() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_PERSON, this.personId.toString()); - attr.put(ATTRIBUTE_LINK, (this.linkId == null ? null : this.linkId.toString())); + // linkId, personId handled by superclass if (this.legMode != null) { attr.put(ATTRIBUTE_LEGMODE, this.legMode); } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonEntersVehicleEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonEntersVehicleEvent.java index e862e1c8095..a3e051f44c4 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonEntersVehicleEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonEntersVehicleEvent.java @@ -29,7 +29,7 @@ /** * @author mrieser */ -public class PersonEntersVehicleEvent extends Event implements HasPersonId { +public class PersonEntersVehicleEvent extends Event implements HasPersonId, HasVehicleId { public static final String EVENT_TYPE = "PersonEntersVehicle"; public static final String ATTRIBUTE_PERSON = "person"; @@ -43,7 +43,7 @@ public PersonEntersVehicleEvent(final double time, final Id personId, fi this.personId = personId; this.vehicleId = vehicleId; } - + public Id getVehicleId() { return this.vehicleId; } @@ -55,8 +55,8 @@ public void setVehicleId(Id vehicleId) { @Override public Id getPersonId() { return this.personId; - } - + } + @Override public String getEventType() { return EVENT_TYPE; @@ -64,9 +64,8 @@ public String getEventType() { @Override public Map getAttributes() { - Map attrs = super.getAttributes(); - attrs.put(ATTRIBUTE_PERSON, this.personId.toString()); - attrs.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); - return attrs; + Map atts = super.getAttributes(); + // personId, vehicleId handled by superclass + return atts; } } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonLeavesVehicleEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonLeavesVehicleEvent.java index c241f9753e3..27a3b5b2bdd 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonLeavesVehicleEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonLeavesVehicleEvent.java @@ -30,12 +30,12 @@ * * @author mrieser */ -public class PersonLeavesVehicleEvent extends Event implements HasPersonId { +public class PersonLeavesVehicleEvent extends Event implements HasPersonId, HasVehicleId { public static final String EVENT_TYPE = "PersonLeavesVehicle"; public static final String ATTRIBUTE_PERSON = "person"; public static final String ATTRIBUTE_VEHICLE = "vehicle"; - + private final Id personId; private Id vehicleId; @@ -44,12 +44,12 @@ public class PersonLeavesVehicleEvent extends Event implements HasPersonId { this.personId = personId; this.vehicleId = vehicleId; } - + @Override public Id getPersonId() { return this.personId; } - + public Id getVehicleId() { return this.vehicleId; } @@ -62,12 +62,11 @@ public void setVehicleId(Id vehicleId) { public String getEventType() { return EVENT_TYPE; } - + @Override public Map getAttributes() { Map attrs = super.getAttributes(); - attrs.put(ATTRIBUTE_PERSON, this.personId.toString()); - attrs.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); + // personId, vehicleId handled by superclass return attrs; } } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonStuckEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonStuckEvent.java index 150495b08e9..b2439dd8b96 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/PersonStuckEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/PersonStuckEvent.java @@ -26,10 +26,10 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.api.core.v01.population.Person; -public class PersonStuckEvent extends Event implements HasPersonId { +public class PersonStuckEvent extends Event implements HasPersonId, HasLinkId { public static final String EVENT_TYPE = "stuckAndAbort"; - + public static final String ATTRIBUTE_LINK = "link"; public static final String ATTRIBUTE_LEGMODE = "legMode"; public static final String ATTRIBUTE_PERSON = "person"; @@ -44,11 +44,11 @@ public PersonStuckEvent(final double time, final Id agentId, final Id
  • getPersonId() { return this.personId; } - + public Id getLinkId() { return this.linkId; } @@ -56,22 +56,19 @@ public Id getLinkId() { public String getLegMode() { return this.legMode; } - + @Override public String getEventType() { return EVENT_TYPE; } - + @Override public Map getAttributes() { Map attr = super.getAttributes(); - if (this.linkId != null) { - attr.put(ATTRIBUTE_LINK, this.linkId.toString()); - } + // personId, linkId handled by superclass if (this.legMode != null) { attr.put(ATTRIBUTE_LEGMODE, this.legMode); } - attr.put(ATTRIBUTE_PERSON, this.personId.toString()); return attr; } } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleAbortsEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleAbortsEvent.java index 39e6782cace..a623a758bd0 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleAbortsEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleAbortsEvent.java @@ -26,10 +26,10 @@ import org.matsim.api.core.v01.network.Link; import org.matsim.vehicles.Vehicle; -public class VehicleAbortsEvent extends Event { +public class VehicleAbortsEvent extends Event implements HasLinkId, HasVehicleId { public static final String EVENT_TYPE = "vehicle aborts"; - + public static final String ATTRIBUTE_LINK = "link"; public static final String ATTRIBUTE_VEHICLE = "vehicle"; @@ -41,11 +41,11 @@ public VehicleAbortsEvent(final double time, final Id vehicleId, final this.vehicleId = vehicleId; this.linkId = linkId; } - + public Id getVehicleId() { return this.vehicleId; } - + public Id getLinkId() { return this.linkId; } @@ -54,12 +54,11 @@ public Id getLinkId() { public String getEventType() { return EVENT_TYPE; } - + @Override public Map getAttributes() { - Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_LINK, this.linkId.toString()); - attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); - return attr; + Map atts = super.getAttributes(); + // linkId, vehicleId handled by superclass + return atts; } -} \ No newline at end of file +} diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleEntersTrafficEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleEntersTrafficEvent.java index 3e3968ccd4d..2316507f115 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleEntersTrafficEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleEntersTrafficEvent.java @@ -39,7 +39,7 @@ public class VehicleEntersTrafficEvent extends Event implements HasPersonId, Has private final String networkMode; private final double relativePositionOnLink; - + public VehicleEntersTrafficEvent(final double time, final Id driverId, final Id linkId, Id vehicleId, String networkMode, double relativePositionOnLink) { super(time); this.driverId = driverId; @@ -48,42 +48,38 @@ public VehicleEntersTrafficEvent(final double time, final Id driverId, f this.networkMode = networkMode; this.relativePositionOnLink = relativePositionOnLink; } - + @Override public Id getPersonId() { return this.driverId; - } - + } + @Override public Id getLinkId() { return this.linkId; } - + public Id getVehicleId() { return vehicleId; } - + @Override public String getEventType() { return EVENT_TYPE; } - + public String getNetworkMode() { return networkMode; } - + public double getRelativePositionOnLink() { return relativePositionOnLink; } - + @Override public Map getAttributes() { Map attr = super.getAttributes(); -// attr.put(ATTRIBUTE_DRIVER, this.driverId.toString()); -// attr.put(ATTRIBUTE_LINK, (this.linkId == null ? null : this.linkId.toString())); -// if (this.vehicleId != null) { -// attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); -// } + // personId, linkId, vehicleId handled by superclass if (this.networkMode != null) { attr.put(ATTRIBUTE_NETWORKMODE, networkMode); } diff --git a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleLeavesTrafficEvent.java b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleLeavesTrafficEvent.java index 00f00a4ec80..600c499063d 100644 --- a/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleLeavesTrafficEvent.java +++ b/matsim/src/main/java/org/matsim/api/core/v01/events/VehicleLeavesTrafficEvent.java @@ -53,30 +53,30 @@ public VehicleLeavesTrafficEvent(final double time, final Id driverId, f this.relativePositionOnLink = relativePositionOnLink; } - + @Override public Id getPersonId() { return this.driverId; - } - + } + @Override public Id getLinkId() { return this.linkId; } - + public Id getVehicleId() { return vehicleId; } - + @Override public String getEventType() { return EVENT_TYPE; } - + public String getNetworkMode() { return networkMode; } - + public double getRelativePositionOnLink() { return relativePositionOnLink; } @@ -84,16 +84,11 @@ public double getRelativePositionOnLink() { @Override public Map getAttributes() { Map attr = super.getAttributes(); - attr.put(ATTRIBUTE_DRIVER, this.driverId.toString()); - attr.put(ATTRIBUTE_LINK, (this.linkId == null ? null : this.linkId.toString())); - if (this.vehicleId != null) { - attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString()); - } + // personId, linkId, vehicleId handled by superclass if (this.networkMode != null) { attr.put(ATTRIBUTE_NETWORKMODE, networkMode); } attr.put(ATTRIBUTE_POSITION, Double.toString(this.relativePositionOnLink)); - return attr; } }