Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Java
GTFS Library
Commits
e60c008e
Commit
e60c008e
authored
Oct 01, 2014
by
Zachary Seguin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial commit
parents
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
806 additions
and
0 deletions
+806
-0
.gitignore
.gitignore
+21
-0
lib/opencsv-3.0.jar
lib/opencsv-3.0.jar
+0
-0
src/ca/zacharyseguin/gtfs/Accessibility.java
src/ca/zacharyseguin/gtfs/Accessibility.java
+23
-0
src/ca/zacharyseguin/gtfs/Agency.java
src/ca/zacharyseguin/gtfs/Agency.java
+116
-0
src/ca/zacharyseguin/gtfs/LocationType.java
src/ca/zacharyseguin/gtfs/LocationType.java
+20
-0
src/ca/zacharyseguin/gtfs/Main.java
src/ca/zacharyseguin/gtfs/Main.java
+31
-0
src/ca/zacharyseguin/gtfs/Route.java
src/ca/zacharyseguin/gtfs/Route.java
+142
-0
src/ca/zacharyseguin/gtfs/RouteType.java
src/ca/zacharyseguin/gtfs/RouteType.java
+40
-0
src/ca/zacharyseguin/gtfs/Stop.java
src/ca/zacharyseguin/gtfs/Stop.java
+186
-0
src/ca/zacharyseguin/util/io/CSVParser.java
src/ca/zacharyseguin/util/io/CSVParser.java
+172
-0
src/ca/zacharyseguin/util/io/EnumValue.java
src/ca/zacharyseguin/util/io/EnumValue.java
+20
-0
src/ca/zacharyseguin/util/io/Field.java
src/ca/zacharyseguin/util/io/Field.java
+19
-0
src/ca/zacharyseguin/util/io/UnknownEnumValue.java
src/ca/zacharyseguin/util/io/UnknownEnumValue.java
+16
-0
No files found.
.gitignore
0 → 100644
View file @
e60c008e
*.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
lib/opencsv-3.0.jar
0 → 100644
View file @
e60c008e
File added
src/ca/zacharyseguin/gtfs/Accessibility.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/gtfs/Agency.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/gtfs/LocationType.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/gtfs/Main.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/gtfs/Route.java
0 → 100644
View file @
e60c008e
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
;
}
}
src/ca/zacharyseguin/gtfs/RouteType.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/gtfs/Stop.java
0 → 100644
View file @
e60c008e
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
src/ca/zacharyseguin/util/io/CSVParser.java
0 → 100644
View file @
e60c008e
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
();