Commit e3f7802c authored by Zachary Seguin's avatar Zachary Seguin

WIP

parent e60c008e
Manifest-Version: 1.0
Main-Class: ca.zacharyseguin.gtfs.Main
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.EnumValue;
import ca.zacharyseguin.util.io.UnknownEnumValue;
/**
* Created by zachary on 14-10-02.
*/
public enum CoordinationType
{
@EnumValue(0)
@UnknownEnumValue
SCHEDULED,
@EnumValue(1)
NONE_AVAILABLE,
@EnumValue(2)
PHONE_AGENCY,
@EnumValue(3)
COORDINATE_WITH_DRIVER
}// End of enum
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.EnumValue;
import ca.zacharyseguin.util.io.UnknownEnumValue;
/**
* The direction of a trip, distinguishing different directions for the same route ID.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public enum Direction
{
@EnumValue(0)
@UnknownEnumValue
OUTBOUND,
@EnumValue(1)
INBOUND
}// End of enum
\ No newline at end of file
......@@ -11,20 +11,13 @@ public class Main
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);
List<Trip> trips = CSVParser.parse("/Users/zachary/tmp/grt_gtfs/trips.txt", Trip.class);
List<StopTime> stopTimes = CSVParser.parse("/Users/zachary/tmp/grt_gtfs/stop_times.txt", StopTime.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());
}
System.out.println("Loaded " + agencies.size() + " agencies.");
System.out.println("Loaded " + routes.size() + " routes.");
System.out.println("Loaded " + stops.size() + " stops.");
System.out.println("Loaded " + trips.size() + " trips.");
System.out.println("Loaded " + stopTimes.size() + " stop times.");
}// End of main method
}// End of class
\ No newline at end of file
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.Field;
/**
* Time that a vehicle arrives and departs from a stop.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public class StopTime
{
@Field("trip_id")
private String tripId;
@Field("arrival_time")
private String arrivalTime;
@Field("departure_time")
private String departureTime;
@Field("stop_id")
private String stopId;
@Field("stop_sequence")
private int sequence;
@Field("stop_headsign")
private String headsign;
@Field("pickup_type")
private CoordinationType pickupType;
@Field("drop_off_type")
private CoordinationType dropOffType;
@Field("shape_dist_traveled")
private double shapeDistanceTraveled;
public StopTime()
{
this.tripId = null;
this.arrivalTime = null;
this.departureTime = null;
this.stopId = null;
this.sequence = 0;
this.headsign = null;
this.pickupType = CoordinationType.SCHEDULED;
this.dropOffType = CoordinationType.SCHEDULED;
this.shapeDistanceTraveled = 0.0;
}// End of constructor
public String getTripId()
{
return tripId;
}
public void setTripId(String tripId)
{
this.tripId = tripId;
}
public String getArrivalTime()
{
return arrivalTime;
}
public void setArrivalTime(String arrivalTime)
{
this.arrivalTime = arrivalTime;
}
public String getDepartureTime()
{
return departureTime;
}
public void setDepartureTime(String departureTime)
{
this.departureTime = departureTime;
}
public String getStopId()
{
return stopId;
}
public void setStopId(String stopId)
{
this.stopId = stopId;
}
public int getSequence()
{
return sequence;
}
public void setSequence(int sequence)
{
this.sequence = sequence;
}
public String getHeadsign()
{
return headsign;
}
public void setHeadsign(String headsign)
{
this.headsign = headsign;
}
public CoordinationType getPickupType()
{
return pickupType;
}
public void setPickupType(CoordinationType pickupType)
{
this.pickupType = pickupType;
}
public CoordinationType getDropOffType()
{
return dropOffType;
}
public void setDropOffType(CoordinationType dropOffType)
{
this.dropOffType = dropOffType;
}
public double getShapeDistanceTraveled()
{
return shapeDistanceTraveled;
}
public void setShapeDistanceTraveled(double shapeDistanceTraveled)
{
this.shapeDistanceTraveled = shapeDistanceTraveled;
}
}// End of class
package ca.zacharyseguin.gtfs;
import ca.zacharyseguin.util.io.Field;
/**
* Individual trip of a route.
*
* @author Zachary Seguin (development@zacharyseguin.ca)
* @version GTFS - June 20, 2012
*/
public class Trip
{
@Field("trip_id")
public String id;
@Field("service_id")
public String serviceId;
@Field("trip_headsign")
public String headsign;
@Field("trip_short_name")
public String shortName;
@Field("direction_id")
public Direction direction;
@Field("block_id")
public String blockId;
@Field("shape_id")
public String shapeId;
@Field("wheelchair_accessible")
public Accessibility wheelchairAccessible;
@Field("bikes_allowed")
public Accessibility bikesAllowed;
public Trip()
{
this.id = null;
this.serviceId = null;
this.headsign = null;
this.shortName = null;
this.direction = Direction.OUTBOUND;
this.blockId = null;
this.shapeId = null;
this.wheelchairAccessible = Accessibility.NO_INFORMATION;
this.bikesAllowed = Accessibility.NO_INFORMATION;
}
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public String getServiceId()
{
return serviceId;
}
public void setServiceId(String serviceId)
{
this.serviceId = serviceId;
}
public String getHeadsign()
{
return headsign;
}
public void setHeadsign(String headsign)
{
this.headsign = headsign;
}
public String getShortName()
{
return shortName;
}
public void setShortName(String shortName)
{
this.shortName = shortName;
}
public Direction getDirection()
{
return direction;
}
public void setDirection(Direction direction)
{
this.direction = direction;
}
public String getBlockId()
{
return blockId;
}
public void setBlockId(String blockId)
{
this.blockId = blockId;
}
public String getShapeId()
{
return shapeId;
}
public void setShapeId(String shapeId)
{
this.shapeId = shapeId;
}
public Accessibility getWheelchairAccessible()
{
return wheelchairAccessible;
}
public void setWheelchairAccessible(Accessibility wheelchairAccessible)
{
this.wheelchairAccessible = wheelchairAccessible;
}
public Accessibility getBikesAllowed()
{
return bikesAllowed;
}
public void setBikesAllowed(Accessibility bikesAllowed)
{
this.bikesAllowed = bikesAllowed;
}
}// End of class
......@@ -76,6 +76,9 @@ public class CSVParser
{
try
{
if (row[x].equals(""))
row[x] = "0";
// TODO: Add other primitive datatypes.
if (setter.type == int.class)
setter.method.invoke(object, Integer.parseInt(row[x]));
......@@ -89,50 +92,58 @@ public class CSVParser
}// End of if
else if (setter.type.isEnum())
{
boolean set = false;
java.lang.reflect.Field unknownField = null;
int value = Integer.parseInt(row[x]);
java.lang.reflect.Field[] enumValues = setter.type.getDeclaredFields();
for (java.lang.reflect.Field enumValue : enumValues)
try
{
EnumValue annotation = (EnumValue)enumValue.getAnnotation(EnumValue.class);
UnknownEnumValue unknownAnnotation = (UnknownEnumValue)enumValue.getAnnotation(UnknownEnumValue.class);
boolean set = false;
if (unknownAnnotation != null)
{
unknownField = enumValue;
}// End of if
java.lang.reflect.Field unknownField = null;
int value = Integer.parseInt(row[x]);
try
java.lang.reflect.Field[] enumValues = setter.type.getDeclaredFields();
for (java.lang.reflect.Field enumValue : enumValues)
{
if (annotation != null && annotation.value() == value)
EnumValue annotation = (EnumValue)enumValue.getAnnotation(EnumValue.class);
UnknownEnumValue unknownAnnotation = (UnknownEnumValue)enumValue.getAnnotation(UnknownEnumValue.class);
if (unknownAnnotation != null)
{
setter.method.invoke(object, Enum.valueOf(setter.type, enumValue.getName()));
set = true;
break;
unknownField = enumValue;
}// End of if
}// End of try
catch (InvocationTargetException e)
{
}// End of catch
}// End of for
try
{
if (annotation != null && annotation.value() == value)
{
setter.method.invoke(object, Enum.valueOf(setter.type, enumValue.getName()));
set = true;
break;
}// End of if
}// End of try
catch (InvocationTargetException e)
{
if (!set)
{
try
}// End of catch
}// End of for
if (!set)
{
if (unknownField != null)
try
{
if (unknownField != null)
{
setter.method.invoke(object, Enum.valueOf(setter.type, unknownField.getName()));
}// End of if
}// End of try
catch (Exception e)
{
setter.method.invoke(object, Enum.valueOf(setter.type, unknownField.getName()));
}// End of if
}// End of try
catch (Exception e)
{
}// End of catch
}// End of if
}// End of catch
}// End of if
}// End of try
catch (Exception e)
{
}// End of catch
}// End of else if
else
{
......
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