Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor GTFS-Flex-specific fields out of PatternHop; create new Flex…
…PatternHop class
- Loading branch information
Showing
11 changed files
with
199 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/org/opentripplanner/routing/edgetype/FlexPatternHop.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,121 @@ | |||
package org.opentripplanner.routing.edgetype; | |||
|
|||
import com.vividsolutions.jts.geom.Geometry; | |||
import org.opentripplanner.model.Stop; | |||
import org.opentripplanner.routing.vertextype.PatternStopVertex; | |||
|
|||
/** A PatternHop with GTFS-Flex service enabled. */ | |||
public class FlexPatternHop extends PatternHop { | |||
|
|||
private static final long serialVersionUID = 1L; | |||
|
|||
private RequestStops requestPickup = RequestStops.NO; | |||
|
|||
private RequestStops requestDropoff = RequestStops.NO; | |||
|
|||
private double serviceAreaRadius = 0d; | |||
|
|||
private Geometry serviceArea = null; | |||
|
|||
public FlexPatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex) { | |||
super(from, to, begin, end, stopIndex, true); | |||
} | |||
|
|||
protected FlexPatternHop(PatternStopVertex from, PatternStopVertex to, Stop begin, Stop end, int stopIndex, boolean setInPattern) { | |||
super(from, to, begin, end, stopIndex, setInPattern); | |||
} | |||
|
|||
/** | |||
* Return the permissions associated with unscheduled pickups in between the endpoints of this | |||
* PatternHop. This relates to flag-stops in the GTFS-Flex specification; if flex and/or flag | |||
* stops are not enabled, this will always be RequestStops.NO. | |||
*/ | |||
public RequestStops getRequestPickup() { | |||
return requestPickup; | |||
} | |||
|
|||
/** | |||
* Return the permissions associated with unscheduled dropoffs in between the endpoints of this | |||
* PatternHop. This relates to flag-stops in the GTFS-Flex specification; if flex and/or flag | |||
* stops are not enabled, this will always be RequestStops.NO. | |||
*/ | |||
public RequestStops getRequestDropoff() { | |||
return requestDropoff; | |||
} | |||
|
|||
/** | |||
* Return whether flag stops are enabled in this hop. Flag stops are enabled if either pickups | |||
* or dropoffs at unscheduled locations can be requested. This is a GTFS-Flex feature. | |||
*/ | |||
private boolean hasFlagStopService() { | |||
return requestPickup.allowed() || requestDropoff.allowed(); | |||
} | |||
|
|||
@Override | |||
public boolean hasFlexService() { | |||
return hasFlagStopService() || getServiceAreaRadius() > 0 || getServiceArea() != null; | |||
} | |||
|
|||
public boolean canRequestService(boolean boarding) { | |||
return boarding ? requestPickup.allowed() : requestDropoff.allowed(); | |||
} | |||
|
|||
public double getServiceAreaRadius() { | |||
return serviceAreaRadius; | |||
} | |||
|
|||
public Geometry getServiceArea() { | |||
return serviceArea; | |||
} | |||
|
|||
public boolean hasServiceArea() { | |||
return serviceArea != null; | |||
} | |||
|
|||
public void setRequestPickup(RequestStops requestPickup) { | |||
this.requestPickup = requestPickup; | |||
} | |||
|
|||
public void setRequestPickup(int code) { | |||
setRequestPickup(RequestStops.fromGtfs(code)); | |||
} | |||
|
|||
public void setRequestDropoff(RequestStops requestDropoff) { | |||
this.requestDropoff = requestDropoff; | |||
} | |||
|
|||
public void setRequestDropoff(int code) { | |||
setRequestDropoff(RequestStops.fromGtfs(code)); | |||
} | |||
|
|||
public void setServiceAreaRadius(double serviceAreaRadius) { | |||
this.serviceAreaRadius = serviceAreaRadius; | |||
} | |||
|
|||
public void setServiceArea(Geometry serviceArea) { | |||
this.serviceArea = serviceArea; | |||
} | |||
|
|||
private enum RequestStops { | |||
NO(1), YES(0), PHONE(2), COORDINATE_WITH_DRIVER(3); | |||
|
|||
final int gtfsCode; | |||
|
|||
RequestStops(int gtfsCode) { | |||
this.gtfsCode = gtfsCode; | |||
} | |||
|
|||
private static RequestStops fromGtfs(int code) { | |||
for (RequestStops it : values()) { | |||
if(it.gtfsCode == code) { | |||
return it; | |||
} | |||
} | |||
return NO; | |||
} | |||
|
|||
boolean allowed() { | |||
return this != NO; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.