Commit e60c008e authored by Zachary Seguin's avatar Zachary Seguin

Initial commit

parents
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# IntelliJ Idea
.idea
out
*.iml
# OS X
.DS_Store
\ No newline at end of file
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.EnumValue;
import ca.zacharyseguin.util.io.UnknownEnumValue;
/**
* Accessibility information.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public enum Accessibility
{
@EnumValue(0)
@UnknownEnumValue
NO_INFORMATION,
@EnumValue(1)
AVAILABLE,
@EnumValue(2)
NOT_AVAILABILE
}// End of enum
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.Field;
import java.net.URL;
/**
* The agency for which schedule data has been provided for.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public class Agency
{
@Field("agency_id")
private String id;
@Field("agency_name")
private String name;
@Field("agency_url")
private URL url;
@Field("agency_timezone")
private String timezone;
@Field("agency_lang")
private String language;
@Field("agency_phone")
private String phone;
@Field("agency_fare_url")
private URL fareUrl;
public Agency()
{
this.id = null;
this.name = null;
this.url = null;
this.timezone = null;
this.language = null;
this.phone = null;
this.fareUrl = null;
}// End of constructor method
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public URL getUrl()
{
return url;
}
public void setUrl(URL url)
{
this.url = url;
}
public String getTimezone()
{
return timezone;
}
public void setTimezone(String timezone)
{
this.timezone = timezone;
}
public String getLanguage()
{
return language;
}
public void setLanguage(String language)
{
this.language = language;
}
public String getPhone()
{
return phone;
}
public void setPhone(String phone)
{
this.phone = phone;
}
public URL getFareUrl()
{
return fareUrl;
}
public void setFareUrl(URL fareUrl)
{
this.fareUrl = fareUrl;
}
}// End of Agency class
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.EnumValue;
import ca.zacharyseguin.util.io.UnknownEnumValue;
/**
* The location type indicating if a stop is a stop or a station.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public enum LocationType
{
@EnumValue(0)
@UnknownEnumValue
STOP,
@EnumValue(1)
STATION
}// End of enum
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.CSVParser;
import java.util.List;
public class Main
{
public static void main(String[] args) throws Exception
{
List<Agency> agencies = CSVParser.parse("/Users/zachary/tmp/grt_gtfs/agency.txt", Agency.class);
List<Route> routes = CSVParser.parse("/Users/zachary/tmp/grt_gtfs/routes.txt", Route.class);
List<Stop> stops = CSVParser.parse("/Users/zachary/tmp/grt_gtfs/stops.txt", Stop.class);
for (Agency agency : agencies)
{
System.out.println(agency.getName());
}
for (Route route : routes)
{
System.out.println(route.getShortName() + " - " + route.getLongName() + " (" + route.getType().toString() + ")");
}
for (Stop stop : stops)
{
System.out.println(stop.getId() + " - " + stop.getName());
}
}// End of main method
}// End of class
\ No newline at end of file
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.Field;
/**
* Transit route.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public class Route
{
@Field("route_id")
private String id;
@Field("agency_id")
private String agencyId;
@Field("route_short_name")
private String shortName;
@Field("route_long_name")
private String longName;
@Field("route_desc")
private String description;
@Field("route_type")
private RouteType type;
@Field("route_url")
private String url;
@Field("route_color")
private String colour;
@Field("route_text_color")
private String textColour;
public Route()
{
this.id = null;
this.agencyId = null;
this.shortName = null;
this.longName = null;
this.description = null;
this.type = RouteType.UNKNOWN;
this.url = null;
this.colour = null;
this.textColour = null;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getAgencyId()
{
return agencyId;
}
public void setAgencyId(String agencyId)
{
this.agencyId = agencyId;
}
public String getShortName()
{
return shortName;
}
public void setShortName(String shortName)
{
this.shortName = shortName;
}
public String getLongName()
{
return longName;
}
public void setLongName(String longName)
{
this.longName = longName;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public RouteType getType()
{
return type;
}
public void setType(RouteType type)
{
this.type = type;
}
public String getUrl()
{
return url;
}
public void setUrl(String url)
{
this.url = url;
}
public String getColour()
{
return colour;
}
public void setColour(String colour)
{
this.colour = colour;
}
public String getTextColour()
{
return textColour;
}
public void setTextColour(String textColour)
{
this.textColour = textColour;
}
}
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.EnumValue;
import ca.zacharyseguin.util.io.UnknownEnumValue;
/**
* The type of transportation used on a route.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public enum RouteType
{
@EnumValue(0)
LIGHT_RAIL,
@EnumValue(1)
SUBWAY,
@EnumValue(2)
RAIL,
@EnumValue(3)
BUS,
@EnumValue(4)
FERRY,
@EnumValue(5)
CABLE_CAR,
@EnumValue(6)
SUSPENDED_CABLE_CAR,
@EnumValue(7)
FUNICULAR,
@UnknownEnumValue
UNKNOWN
}// End of enum
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.Field;
import java.net.URL;
/**
* Location where vehicles pick up or drop off passengers.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public class Stop
{
@Field("stop_id")
private String id;
@Field("stop_code")
private String code;
@Field("stop_name")
private String name;
@Field("stop_desc")
private String description;
@Field("stop_lat")
private Double latitude;
@Field("stop_lon")
private Double longitiude;
@Field("zone_id")
private String zoneId;
@Field("stop_url")
private URL url;
@Field("location_type")
private LocationType type;
@Field("parent_station")
private String parentStation;
@Field("stop_timezone")
private String timezone;
@Field("wheelchair_boarding")
private Accessibility wheelchairBoarding;
public Stop()
{
this.id = null;
this.code = null;
this.name = null;
this.description = null;
this.latitude = 0.0;
this.longitiude = 0.0;
this.zoneId = null;
this.url = null;
this.type = null;
this.parentStation = null;
this.timezone = null;
this.wheelchairBoarding = Accessibility.NO_INFORMATION;
}// End of constructor
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getCode()
{
return code;
}
public void setCode(String code)
{
this.code = code;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public String getDescription()
{
return description;
}
public void setDescription(String description)
{
this.description = description;
}
public Double getLatitude()
{
return latitude;
}
public void setLatitude(Double latitude)
{
this.latitude = latitude;
}
public Double getLongitiude()
{
return longitiude;
}
public void setLongitiude(Double longitiude)
{
this.longitiude = longitiude;
}
public String getZoneId()
{
return zoneId;
}
public void setZoneId(String zoneId)
{
this.zoneId = zoneId;
}
public URL getUrl()
{
return url;
}
public void setUrl(URL url)
{
this.url = url;
}
public LocationType getType()
{
return type;
}
public void setType(LocationType type)
{
this.type = type;
}
public String getParentStation()
{
return parentStation;
}
public void setParentStation(String parentStation)
{
this.parentStation = parentStation;
}
public String getTimezone()
{
return timezone;
}
public void setTimezone(String timezone)
{
this.timezone = timezone;
}
public Accessibility getWheelchairBoarding()
{
return wheelchairBoarding;
}
public void setWheelchairBoarding(Accessibility wheelchairBoarding)
{
this.wheelchairBoarding = wheelchairBoarding;
}
}// End of class
package ca.zacharyseguin.util.io;
import au.com.bytecode.opencsv.CSVReader;
import java.io.FileReader;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class CSVParser
{
private static class Setter
{
public Method method;
public Class type;
}
public static <T> List<T> parse(String filename, Class<T> type) throws IOException, NoSuchMethodException
{
List<T> objects = new ArrayList<T>();
Map<String, Setter> setters = new HashMap<String, Setter>();
// Decode fields
java.lang.reflect.Field[] fields = type.getDeclaredFields();
for (java.lang.reflect.Field field : fields)
{
Field annotation = (Field)field.getAnnotation(Field.class);
if (annotation != null)
{
String setterName = field.getName();