Skip to content

Commit

Permalink
core: simplify getAttributes() in core events
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmac committed Dec 27, 2023
1 parent ac39700 commit 47d5d30
Show file tree
Hide file tree
Showing 10 changed files with 75 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -49,29 +49,28 @@ public LinkEnterEvent(final double time, final Id<Vehicle> vehicleId, final Id<L
public String getEventType() {
return EVENT_TYPE;
}

/**
* Please use getVehicleId() instead.
* Please use getVehicleId() instead.
* Vehicle-driver relations can be made by {@link VehicleEntersTrafficEvent} and {@link VehicleLeavesTrafficEvent}.
*/
@Deprecated
public Id<Person> getDriverId() {
throw new RuntimeException( LinkLeaveEvent.missingDriverIdMessage ) ;
}
}
@Override
public Id<Link> getLinkId() {
return this.linkId;
}

public Id<Vehicle> getVehicleId() {
return vehicleId;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString());
attr.put(ATTRIBUTE_LINK, this.linkId.toString());
return attr;
Map<String, String> atts = super.getAttributes();
// linkId, vehicleId handled by superclass
return atts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand All @@ -69,12 +69,11 @@ public Id<Link> getLinkId() {
public Id<Vehicle> getVehicleId() {
return vehicleId;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString());
attr.put(ATTRIBUTE_LINK, this.linkId.toString());
return attr;
Map<String, String> atts = super.getAttributes();
// linkId, vehicleId handled by superclass
return atts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -45,28 +45,27 @@ public PersonArrivalEvent(final double time, final Id<Person> agentId, final Id<
this.legMode = legMode;
this.personId = agentId;
}

public Id<Person> getPersonId() {
return this.personId;
}

public Id<Link> getLinkId() {
return this.linkId;
}

public String getLegMode() {
return this.legMode;
}

public String getEventType() {
return EVENT_TYPE;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -47,24 +47,24 @@ public PersonDepartureEvent(final double time, final Id<Person> agentId, final I
this.personId = agentId;
this.routingMode = routingMode;
}

@Override
public Id<Person> getPersonId() {
return this.personId;
}

public Id<Link> getLinkId() {
return this.linkId;
}

public String getLegMode() {
return this.legMode;
}

public String getRoutingMode() {
return routingMode;
}

@Override
public String getEventType() {
return EVENT_TYPE;
Expand All @@ -73,8 +73,7 @@ public String getEventType() {
@Override
public Map<String, String> getAttributes() {
Map<String, String> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -43,7 +43,7 @@ public PersonEntersVehicleEvent(final double time, final Id<Person> personId, fi
this.personId = personId;
this.vehicleId = vehicleId;
}

public Id<Vehicle> getVehicleId() {
return this.vehicleId;
}
Expand All @@ -55,18 +55,17 @@ public void setVehicleId(Id<Vehicle> vehicleId) {
@Override
public Id<Person> getPersonId() {
return this.personId;
}
}

@Override
public String getEventType() {
return EVENT_TYPE;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attrs = super.getAttributes();
attrs.put(ATTRIBUTE_PERSON, this.personId.toString());
attrs.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString());
return attrs;
Map<String, String> atts = super.getAttributes();
// personId, vehicleId handled by superclass
return atts;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Person> personId;
private Id<Vehicle> vehicleId;

Expand All @@ -44,12 +44,12 @@ public class PersonLeavesVehicleEvent extends Event implements HasPersonId {
this.personId = personId;
this.vehicleId = vehicleId;
}

@Override
public Id<Person> getPersonId() {
return this.personId;
}

public Id<Vehicle> getVehicleId() {
return this.vehicleId;
}
Expand All @@ -62,12 +62,11 @@ public void setVehicleId(Id<Vehicle> vehicleId) {
public String getEventType() {
return EVENT_TYPE;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attrs = super.getAttributes();
attrs.put(ATTRIBUTE_PERSON, this.personId.toString());
attrs.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString());
// personId, vehicleId handled by superclass
return attrs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -44,34 +44,31 @@ public PersonStuckEvent(final double time, final Id<Person> agentId, final Id<Li
this.linkId = linkId;
this.legMode = legMode;
}

public Id<Person> getPersonId() {
return this.personId;
}

public Id<Link> getLinkId() {
return this.linkId;
}

public String getLegMode() {
return this.legMode;
}

@Override
public String getEventType() {
return EVENT_TYPE;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -41,11 +41,11 @@ public VehicleAbortsEvent(final double time, final Id<Vehicle> vehicleId, final
this.vehicleId = vehicleId;
this.linkId = linkId;
}

public Id<Vehicle> getVehicleId() {
return this.vehicleId;
}

public Id<Link> getLinkId() {
return this.linkId;
}
Expand All @@ -54,12 +54,11 @@ public Id<Link> getLinkId() {
public String getEventType() {
return EVENT_TYPE;
}

@Override
public Map<String, String> getAttributes() {
Map<String, String> attr = super.getAttributes();
attr.put(ATTRIBUTE_LINK, this.linkId.toString());
attr.put(ATTRIBUTE_VEHICLE, this.vehicleId.toString());
return attr;
Map<String, String> atts = super.getAttributes();
// linkId, vehicleId handled by superclass
return atts;
}
}
}
Loading

0 comments on commit 47d5d30

Please sign in to comment.