Commit 7e9f9a07 authored by Zachary Seguin's avatar Zachary Seguin

Added ability to get stop times for a trip

parent 6616a264
......@@ -166,21 +166,42 @@ public class GTFS
* @param serviceId Service id to find trips for.
* @return List of trips with a service id matching serviceId.
*/
public List<Trip> trips(String serviceId)
public Map<String, Trip> trips(String serviceId)
{
List<Trip> trips = new ArrayList<Trip>();
Map<String, Trip> trips = new HashMap<String, Trip>();
for (Trip trip : this.trips.values())
{
if (trip.getServiceId().equals(serviceId))
{
trips.add(trip);
trips.put(trip.getId(), trip);
}// End of if
}// End of for
return trips;
}// End of trips method
/**
* Returns a list of stop times for a trip.
*
* @param tripId The trip id to get stop times for.
* @return A map where the key is the stopID and the value is the StopTime object.
*/
public Map<String, StopTime> stopTimes(String tripId)
{
Map<String, StopTime> stopTimes = new LinkedHashMap<String, StopTime>();
for (StopTime stopTime : this.stopTimes)
{
if (stopTime.getTripId().equals(tripId))
{
stopTimes.put(stopTime.getStopId(), stopTime);
}// End of if
}// End of for
return stopTimes;
}// End of stopTimes method
public Map<String, Agency> getAgencies()
{
return agencies;
......
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.CSVParser;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
public class Main
{
......@@ -24,12 +22,23 @@ public class Main
List<String> serviceIds = gtfs.activeServiceIDs();
for (String serviceId : serviceIds)
{
List<Trip> trips = gtfs.trips(serviceId);
System.out.println(serviceId);
Map<String, Trip> trips = gtfs.trips(serviceId);
for (Trip trip : trips)
for (Trip trip : trips.values())
{
System.out.println(trip.getId() + " - " + trip.getHeadsign());
Map<String, StopTime> stopTimes = gtfs.stopTimes(trip.getId());
for (StopTime stopTime : stopTimes.values())
{
System.out.println(stopTime.getSequence() + " - " + stopTime.getStopId() + " - " + stopTime.getDepartureTime());
}// End of for
System.out.println();
}// End of for
System.out.println();
}
}// End of main method
}// End of class
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment