Skip to content

Commit

Permalink
Remove ids from Value Objects and other none Entity classes in the OT…
Browse files Browse the repository at this point in the history
…P Tranist model - Note these objects do

not have ids in the GTFS model.
(Refactor OTP to have new OTP classes to replace the OBA GTFS classes #2494)
  • Loading branch information
Thomas Gran committed Nov 28, 2017
1 parent 762a593 commit f6d27f1
Show file tree
Hide file tree
Showing 24 changed files with 163 additions and 127 deletions.
Expand Up @@ -46,7 +46,6 @@ FareRule map(org.onebusaway.gtfs.model.FareRule orginal) {
private FareRule doMap(org.onebusaway.gtfs.model.FareRule rhs) {
FareRule lhs = new FareRule();

lhs.setId(rhs.getId());
lhs.setFare(fareAttributeMapper.map(rhs.getFare()));
lhs.setRoute(routeMapper.map(rhs.getRoute()));
lhs.setOriginId(rhs.getOriginId());
Expand Down
Expand Up @@ -40,7 +40,6 @@ Frequency map(org.onebusaway.gtfs.model.Frequency orginal) {
private Frequency doMap(org.onebusaway.gtfs.model.Frequency rhs) {
Frequency lhs = new Frequency();

lhs.setId(rhs.getId());
lhs.setTrip(tripMapper.map(rhs.getTrip()));
lhs.setStartTime(rhs.getStartTime());
lhs.setEndTime(rhs.getEndTime());
Expand Down
Expand Up @@ -35,7 +35,6 @@ ServiceCalendarDate map(org.onebusaway.gtfs.model.ServiceCalendarDate orginal) {
private ServiceCalendarDate doMap(org.onebusaway.gtfs.model.ServiceCalendarDate rhs) {
ServiceCalendarDate lhs = new ServiceCalendarDate();

lhs.setId(rhs.getId());
lhs.setServiceId(AgencyAndIdMapper.mapAgencyAndId(rhs.getServiceId()));
lhs.setDate(ServiceDateMapper.mapServiceDate(rhs.getDate()));
lhs.setExceptionType(rhs.getExceptionType());
Expand Down
Expand Up @@ -37,7 +37,6 @@ ServiceCalendar map(org.onebusaway.gtfs.model.ServiceCalendar orginal) {
private ServiceCalendar doMap(org.onebusaway.gtfs.model.ServiceCalendar rhs) {
ServiceCalendar lhs = new ServiceCalendar();

lhs.setId(rhs.getId());
lhs.setServiceId(mapAgencyAndId(rhs.getServiceId()));
lhs.setMonday(rhs.getMonday());
lhs.setTuesday(rhs.getTuesday());
Expand Down
Expand Up @@ -34,7 +34,6 @@ ShapePoint map(org.onebusaway.gtfs.model.ShapePoint orginal) {
private ShapePoint doMap(org.onebusaway.gtfs.model.ShapePoint rhs) {
ShapePoint lhs = new ShapePoint();

lhs.setId(rhs.getId());
lhs.setShapeId(AgencyAndIdMapper.mapAgencyAndId(rhs.getShapeId()));
lhs.setSequence(rhs.getSequence());
lhs.setLat(rhs.getLat());
Expand Down
Expand Up @@ -43,9 +43,6 @@ StopTime map(org.onebusaway.gtfs.model.StopTime orginal) {
private StopTime doMap(org.onebusaway.gtfs.model.StopTime rhs) {
StopTime lhs = new StopTime();

lhs.setId(rhs.getId());

lhs.setId(rhs.getId());
lhs.setTrip(tripMapper.map(rhs.getTrip()));
lhs.setStop(stopMapper.map(rhs.getStop()));
lhs.setArrivalTime(rhs.getArrivalTime());
Expand Down
Expand Up @@ -46,9 +46,6 @@ Transfer map(org.onebusaway.gtfs.model.Transfer orginal) {
private Transfer doMap(org.onebusaway.gtfs.model.Transfer rhs) {
Transfer lhs = new Transfer();

lhs.setId(rhs.getId());

lhs.setId(rhs.getId());
lhs.setFromStop(stopMapper.map(rhs.getFromStop()));
lhs.setFromRoute(routeMapper.map(rhs.getFromRoute()));
lhs.setFromTrip(tripMapper.map(rhs.getFromTrip()));
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/org/opentripplanner/model/FareRule.java
Expand Up @@ -15,11 +15,11 @@
*/
package org.opentripplanner.model;

public final class FareRule extends IdentityBean<Integer> {
import java.io.Serializable;

private static final long serialVersionUID = 1L;
public final class FareRule implements Serializable {

private int id;
private static final long serialVersionUID = 1L;

private FareAttribute fare;

Expand All @@ -31,16 +31,6 @@ public final class FareRule extends IdentityBean<Integer> {

private String containsId;

@Override
public Integer getId() {
return id;
}

@Override
public void setId(Integer id) {
this.id = id;
}

public FareAttribute getFare() {
return fare;
}
Expand Down Expand Up @@ -82,6 +72,20 @@ public void setContainsId(String containsId) {
}

public String toString() {
return "<FareRule " + getId() + ">";
return "<FareRule "
+ toStrOpt(" route=", route)
+ toStrOpt(" origin=", originId)
+ toStrOpt(" contains=", containsId)
+ toStrOpt(" destination=", destinationId)
+ ">";
}


private static String toStrOpt(String lbl, IdentityBean arg) {
return (arg == null ? "" : lbl + arg.getId());
}

private static String toStrOpt(String lbl, String arg) {
return (arg == null ? "" : lbl + '\'' + arg + '\'');
}
}
35 changes: 21 additions & 14 deletions src/main/java/org/opentripplanner/model/Frequency.java
Expand Up @@ -16,14 +16,15 @@
*/
package org.opentripplanner.model;

import java.io.Serializable;
import java.util.Objects;

import static org.opentripplanner.util.TimeToStringConverter.toHH_MM_SS;

public final class Frequency extends IdentityBean<Integer> {
public final class Frequency implements Serializable {

private static final long serialVersionUID = 1L;

private int id;

private Trip trip;

private int startTime;
Expand All @@ -36,16 +37,6 @@ public final class Frequency extends IdentityBean<Integer> {

private int labelOnly = 0;

@Override
public Integer getId() {
return id;
}

@Override
public void setId(Integer id) {
this.id = id;
}

public Trip getTrip() {
return trip;
}
Expand Down Expand Up @@ -94,8 +85,24 @@ public void setLabelOnly(int labelOnly) {
this.labelOnly = labelOnly;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Frequency frequency = (Frequency) o;
return startTime == frequency.startTime && endTime == frequency.endTime
&& headwaySecs == frequency.headwaySecs && Objects.equals(trip, frequency.trip);
}

@Override
public int hashCode() {
return Objects.hash(trip, startTime, endTime, headwaySecs);
}

public String toString() {
return "<Frequency " + getId()
return "<Frequency trip=" + trip.getId()
+ " start=" + toHH_MM_SS(startTime)
+ " end=" + toHH_MM_SS(endTime)
+ ">";
Expand Down
35 changes: 24 additions & 11 deletions src/main/java/org/opentripplanner/model/ServiceCalendar.java
Expand Up @@ -17,19 +17,20 @@

import org.opentripplanner.model.calendar.ServiceDate;

import java.io.Serializable;
import java.util.Objects;

/**
* Note that I decided to call this class ServiceCalendar instead of Calendar,
* so as to avoid confusion with java.util.Calendar
*
* @author bdferris
*
*/
public final class ServiceCalendar extends IdentityBean<Integer> {
public final class ServiceCalendar implements Serializable {

private static final long serialVersionUID = 1L;

private int id;

private AgencyAndId serviceId;

private int monday;
Expand All @@ -50,14 +51,6 @@ public final class ServiceCalendar extends IdentityBean<Integer> {

private ServiceDate endDate;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public AgencyAndId getServiceId() {
return serviceId;
}
Expand Down Expand Up @@ -138,6 +131,26 @@ public void setEndDate(ServiceDate endDate) {
this.endDate = endDate;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ServiceCalendar that = (ServiceCalendar) o;
return monday == that.monday && tuesday == that.tuesday && wednesday == that.wednesday
&& thursday == that.thursday && friday == that.friday && saturday == that.saturday
&& sunday == that.sunday && Objects.equals(serviceId, that.serviceId) && Objects
.equals(startDate, that.startDate) && Objects.equals(endDate, that.endDate);
}

@Override
public int hashCode() {
return Objects
.hash(serviceId, monday, tuesday, wednesday, thursday, friday, saturday, sunday,
startDate, endDate);
}

public String toString() {
return "<ServiceCalendar " + this.serviceId + " [" + this.monday + this.tuesday
+ this.wednesday + this.thursday + this.friday + this.saturday + this.sunday + "]>";
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/org/opentripplanner/model/ServiceCalendarDate.java
Expand Up @@ -17,34 +17,27 @@

import org.opentripplanner.model.calendar.ServiceDate;

import java.io.Serializable;
import java.util.Objects;

/**
* @author bdferris
*
*/
public final class ServiceCalendarDate extends IdentityBean<Integer> {
public final class ServiceCalendarDate implements Serializable {

private static final long serialVersionUID = 1L;

public static final int EXCEPTION_TYPE_ADD = 1;

public static final int EXCEPTION_TYPE_REMOVE = 2;

private int id;

private AgencyAndId serviceId;

private ServiceDate date;

private int exceptionType;

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public AgencyAndId getServiceId() {
return serviceId;
}
Expand All @@ -69,6 +62,21 @@ public void setExceptionType(int exceptionType) {
this.exceptionType = exceptionType;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ServiceCalendarDate that = (ServiceCalendarDate) o;
return Objects.equals(serviceId, that.serviceId) && Objects.equals(date, that.date);
}

@Override
public int hashCode() {
return Objects.hash(serviceId, date);
}

@Override
public String toString() {
return "<CalendarDate serviceId=" + this.serviceId + " date=" + this.date + " exception="
Expand Down
30 changes: 19 additions & 11 deletions src/main/java/org/opentripplanner/model/ShapePoint.java
Expand Up @@ -15,14 +15,15 @@
*/
package org.opentripplanner.model;

public final class ShapePoint extends IdentityBean<Integer> implements Comparable<ShapePoint> {
import java.io.Serializable;
import java.util.Objects;

public final class ShapePoint implements Serializable, Comparable<ShapePoint> {

private static final long serialVersionUID = 1L;

private static final double MISSING_VALUE = -999;

private int id;

private AgencyAndId shapeId;

private int sequence;
Expand All @@ -36,14 +37,6 @@ public final class ShapePoint extends IdentityBean<Integer> implements Comparabl
public ShapePoint() {
}

public Integer getId() {
return id;
}

public void setId(Integer id) {
this.id = id;
}

public AgencyAndId getShapeId() {
return shapeId;
}
Expand Down Expand Up @@ -97,6 +90,21 @@ public void setLon(double lon) {
this.lon = lon;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ShapePoint that = (ShapePoint) o;
return sequence == that.sequence && Objects.equals(shapeId, that.shapeId);
}

@Override
public int hashCode() {
return Objects.hash(shapeId, sequence);
}

@Override
public String toString() {
return "<ShapePoint " + getShapeId() + " #" + getSequence() + " (" + getLat() + ","
Expand Down

0 comments on commit f6d27f1

Please sign in to comment.