Commit 6616a264 authored by Zachary Seguin's avatar Zachary Seguin

Added ability to get routes by service id

parent 5afadd68
......@@ -4,14 +4,16 @@ import ca.zacharyseguin.util.io.CSVParser;
import java.io.IOException;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* Class for loading, parsing and interacting with GTFS data.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version 1.0 - Oct. 3, 2014
*/
public class GTFS
{
public static String DATE_FORMAT = "yyyyMMdd";
public static String TIME_FORMAT = "HH:mm";
private Map<String, Agency> agencies;
private Map<String, Stop> stops;
private Map<String, Route> routes;
......@@ -20,6 +22,12 @@ public class GTFS
private List<Calendar> calendar;
private List<CalendarDate> calendarDates;
/**
* Constructs the GTFS object, loading in the GTFS data from the specified directory.
*
* @param directory Directory containing the GTFS data files.
* @throws IOException If one of the required files are not provided, an IOException will be thrown.
*/
public GTFS(String directory) throws IOException
{
try
......@@ -142,7 +150,7 @@ public class GTFS
calendarDate.setTime(date);
return this.activeServiceIDs(calendarDate);
}// End of activeServiceIDs
}// End of activeServiceIDs method
/**
* Returns a list of Service IDs for today.
......@@ -151,7 +159,27 @@ public class GTFS
public List<String> activeServiceIDs()
{
return this.activeServiceIDs(GregorianCalendar.getInstance());
}// End of activeServiceIDs
}// End of activeServiceIDs method
/**
* Returns a list of trips for the requested service id.
* @param serviceId Service id to find trips for.
* @return List of trips with a service id matching serviceId.
*/
public List<Trip> trips(String serviceId)
{
List<Trip> trips = new ArrayList<Trip>();
for (Trip trip : this.trips.values())
{
if (trip.getServiceId().equals(serviceId))
{
trips.add(trip);
}// End of if
}// End of for
return trips;
}// End of trips method
public Map<String, Agency> getAgencies()
{
......
......@@ -24,7 +24,12 @@ public class Main
List<String> serviceIds = gtfs.activeServiceIDs();
for (String serviceId : serviceIds)
{
System.out.println(serviceId);
List<Trip> trips = gtfs.trips(serviceId);
for (Trip trip : trips)
{
System.out.println(trip.getId() + " - " + trip.getHeadsign());
}// End of for
}
}// 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