├── .classpath
├── .gitignore
├── .project
├── .settings
├── org.eclipse.jdt.core.prefs
└── org.eclipse.m2e.core.prefs
├── .travis.yml
├── .travis
├── deploysf.sh
├── ssh-key.enc
└── ssh_config
├── LICENSE
├── README.md
├── doc
├── allclasses-frame.html
├── allclasses-noframe.html
├── com
│ ├── github
│ │ └── mob41
│ │ │ └── kmbeta
│ │ │ ├── api
│ │ │ ├── ArrivalManager.html
│ │ │ ├── ArrivalTime.html
│ │ │ ├── BusDatabase.html
│ │ │ ├── BusStop.html
│ │ │ ├── KmbApi.html
│ │ │ ├── MultiArrivalManager.html
│ │ │ ├── Route.html
│ │ │ ├── RouteBound.html
│ │ │ ├── ServerTime.html
│ │ │ ├── Test.html
│ │ │ ├── class-use
│ │ │ │ ├── ArrivalManager.html
│ │ │ │ ├── ArrivalTime.html
│ │ │ │ ├── BusDatabase.html
│ │ │ │ ├── BusStop.html
│ │ │ │ ├── KmbApi.html
│ │ │ │ ├── MultiArrivalManager.html
│ │ │ │ ├── Route.html
│ │ │ │ ├── RouteBound.html
│ │ │ │ ├── ServerTime.html
│ │ │ │ └── Test.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── package-use.html
│ │ │ └── exception
│ │ │ ├── CouldNotLoadDatabaseException.html
│ │ │ ├── DatabaseNotLoadedException.html
│ │ │ ├── FetchRoutesException.html
│ │ │ ├── InvalidArrivalTargetException.html
│ │ │ ├── InvalidException.html
│ │ │ ├── NoETADataFetchedError.html
│ │ │ ├── NoServerTimeFetchedError.html
│ │ │ ├── NoSuchRouteException.html
│ │ │ ├── class-use
│ │ │ ├── CouldNotLoadDatabaseException.html
│ │ │ ├── DatabaseNotLoadedException.html
│ │ │ ├── FetchRoutesException.html
│ │ │ ├── InvalidArrivalTargetException.html
│ │ │ ├── InvalidException.html
│ │ │ ├── NoETADataFetchedError.html
│ │ │ ├── NoServerTimeFetchedError.html
│ │ │ └── NoSuchRouteException.html
│ │ │ ├── package-frame.html
│ │ │ ├── package-summary.html
│ │ │ ├── package-tree.html
│ │ │ └── package-use.html
│ └── mob41
│ │ └── kmbeta
│ │ └── api
│ │ └── tests
│ │ ├── Get2ABusArrival.html
│ │ ├── MultiArrivals.html
│ │ ├── class-use
│ │ ├── Get2ABusArrival.html
│ │ └── MultiArrivals.html
│ │ ├── package-frame.html
│ │ ├── package-summary.html
│ │ ├── package-tree.html
│ │ └── package-use.html
├── constant-values.html
├── deprecated-list.html
├── help-doc.html
├── index-files
│ ├── index-1.html
│ ├── index-10.html
│ ├── index-11.html
│ ├── index-12.html
│ ├── index-13.html
│ ├── index-14.html
│ ├── index-15.html
│ ├── index-16.html
│ ├── index-2.html
│ ├── index-3.html
│ ├── index-4.html
│ ├── index-5.html
│ ├── index-6.html
│ ├── index-7.html
│ ├── index-8.html
│ └── index-9.html
├── index.html
├── overview-frame.html
├── overview-summary.html
├── overview-tree.html
├── package-list
├── script.js
├── serialized-form.html
└── stylesheet.css
├── pom.xml
└── src
├── main
└── java
│ └── com
│ └── github
│ └── mob41
│ └── kmbeta
│ ├── api
│ ├── ArrivalManager.java
│ ├── ArrivalTime.java
│ ├── BusDatabase.java
│ ├── BusStop.java
│ ├── KmbApi.java
│ ├── MultiArrivalManager.java
│ ├── Route.java
│ ├── RouteBound.java
│ ├── ServerTime.java
│ └── Test.java
│ └── exception
│ ├── CouldNotLoadDatabaseException.java
│ ├── DatabaseNotLoadedException.java
│ ├── FetchRoutesException.java
│ ├── InvalidArrivalTargetException.java
│ ├── InvalidException.java
│ ├── NoETADataFetchedError.java
│ ├── NoServerTimeFetchedError.java
│ └── NoSuchRouteException.java
└── test
├── java
└── com
│ └── mob41
│ └── kmbeta
│ └── api
│ └── tests
│ ├── Get2ABusArrival.java
│ └── MultiArrivals.java
└── resources
└── bus_stopdb.properties
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | /target/
2 | !/.travis/
3 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | KmbETA
4 |
5 |
6 |
7 |
8 |
9 | org.eclipse.jdt.core.javabuilder
10 |
11 |
12 |
13 |
14 | org.eclipse.m2e.core.maven2Builder
15 |
16 |
17 |
18 |
19 |
20 | org.eclipse.jdt.core.javanature
21 | org.eclipse.m2e.core.maven2Nature
22 |
23 |
24 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4 | org.eclipse.jdt.core.compiler.compliance=1.8
5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
7 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
8 | org.eclipse.jdt.core.compiler.source=1.8
9 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.m2e.core.prefs:
--------------------------------------------------------------------------------
1 | activeProfiles=
2 | eclipse.preferences.version=1
3 | resolveWorkspaceProjects=true
4 | version=1
5 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: java
2 |
3 | install: true
4 |
5 | before_install:
6 | - openssl aes-256-cbc -K $encrypted_f76c010fc1af_key -iv $encrypted_f76c010fc1af_iv -in .travis/ssh-key.enc -out ~/.ssh/id_rsa -d
7 | - chmod 600 ~/.ssh/id_rsa
8 | - eval $(ssh-agent)
9 | - ssh-add ~/.ssh/id_rsa
10 | - cp .travis/ssh_config ~/.ssh/config
11 | - chmod +x .travis/deploysf.sh
12 | - echo $PUBKEY > ~/.ssh/id_rsa.pub
13 | - ls -a ~/.ssh
14 | - sudo apt-get update
15 | - sudo apt-get install openssh-client zip
16 |
17 | before_deploy:
18 | - echo $projectversion
19 | - git config --global user.email "builds@travis-ci.com"
20 | - git config --global user.name "Travis CI"
21 | - export GIT_TAG=$projectversion-B$TRAVIS_BUILD_NUMBER
22 | - git tag $GIT_TAG -a -m "Development build $TRAVIS_BUILD_NUMBER from Travis-CI"
23 | - git push -q https://$GITPERM@github.com/mob41/KmbETA-API --tags
24 | - ls -l
25 |
26 | deploy:
27 | skip_cleanup: true
28 | provider: releases
29 | api_key: $GITPERM
30 | file:
31 | - KmbETA-API-$projectversion-$TRAVIS_BRANCH-B$TRAVIS_BUILD_NUMBER.zip
32 | on:
33 | tags: false
34 | branch: develop
35 |
36 | after_success:
37 | - mvn package
38 | - cd target
39 | - ls -l
40 | - zip KmbETA-API-$projectversion-$TRAVIS_BRANCH-B$TRAVIS_BUILD_NUMBER.zip KmbETA-API-$projectversion.jar KmbETA-API-$projectversion-jar-with-dependencies.jar KmbETA-API-$projectversion-javadoc.jar
41 | - if [ "$TRAVIS_BRANCH" = "master" ]; then ../.travis/deploysf.sh ; fi
42 |
43 | branches:
44 | only:
45 | - master
46 | - develop
47 |
48 | env:
49 | - projectversion=1.0.0-SNAPSHOT
--------------------------------------------------------------------------------
/.travis/deploysf.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | cp KmbETA-API-$projectversion-$TRAVIS_BRANCH-B$TRAVIS_BUILD_NUMBER.zip KmbETA-API-$projectversion-latest.zip
3 | ls -l
4 | scp -v -i ~/.ssh/id_rsa KmbETA-API-$projectversion-latest.zip mob41,kmbeta-api@frs.sourceforge.net:/home/frs/project/k/km/kmbeta-api
5 |
--------------------------------------------------------------------------------
/.travis/ssh-key.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/a1aw/KmbETA-API/8980c87c2cdcdf543096441a7d50156cd36d7552/.travis/ssh-key.enc
--------------------------------------------------------------------------------
/.travis/ssh_config:
--------------------------------------------------------------------------------
1 | Host frs.sourceforge.net
2 | User mob41,kmbeta-api
3 | StrictHostKeyChecking no
4 | IdentityFile ~/.ssh/id_rsa
5 | IdentitiesOnly yes
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KmbETA-API [](https://travis-ci.org/mob41/KmbETA-API)
2 |
3 | An API client for getting KMB bus's ETA.
4 |
5 | JavaDoc: [http://mob41.github.io/KmbETA-API](http://mob41.github.io/KmbETA-API)
6 |
7 | # No longer maintained
8 |
9 | This project is abandoned and outdated because I have focused on developing it on GoToWhere platform. The latest API implementation is in JavaScript, and at the GoToWhere plugins repository: [gtwp-kmb](https://github.com/mob41/gotowhere-plugins/tree/master/repos/gtwp-kmb)
10 |
11 | The current Java code current should still work. Unless there is serious changes that need to be made, I will not update the code because I don't have time.
12 |
13 | Database builder and KMB database will still keep updated for using in GTW.
14 |
15 | # License
16 |
17 | Based on GNU GENERAL PUBLIC LICENSE Version 3.
18 |
19 | >To "modify" a work means to copy from or adapt all or part of the work
20 | >in a fashion requiring copyright permission, other than the making of an
21 | >exact copy. The resulting work is called a "modified version" of the
22 | >earlier work or a work "based on" the earlier work.
23 |
24 | I would like to clarify this point.
25 |
26 | # Changelog
27 |
28 | ```1.0.0-SNAPSHOT``` Changelog:
29 | - Improved database structure
30 | - Changing to JSON format, more web friendly
31 | - Separating classes in API
32 | - Offline database is no longer required. By default, fetch the [pre-built database](https://github.com/mob41/KmbETA-DB) from the web
33 | - Support for web pre-built database. See [here](https://github.com/mob41/KmbETA-DB). (I call it "static database", but web)
34 | - Support for fetching database information directly (I call it "non-static database")
35 | - Some typo on function names
36 | - Improved some JavaDoc
37 |
38 | # Tutorial
39 |
40 | Check out the wiki [Quick Start](https://github.com/mob41/KmbETA-API/wiki/Quick-Start).
41 |
42 | Offline database is not required since ```1.0.0-SNAPSHOT```. By default, the API will download the web DB from [here](https://github.com/mob41/KmbETA-DB) or [here](https://db.kmbeta.ml) on each launch.
43 |
44 | Offline database can also be used by specifying a parameter to ```ArrivalManager```. (See the [wiki](https://github.com/mob41/KmbETA-API/wiki/Quick-Start)) It is also available to be [built](https://github.com/mob41/KmbETA-API/wiki/How-to-use-the-DBBuilder-(Auto-Mode)) using the [DB-Builder](https://github.com/mob41/KmbETA-DBBuilder) and downloaded from the [repository](https://github.com/mob41/KmbETA-DB) or the [website](https://db.kmbeta.ml/). (They are actually the same) But, now, the API still cannot built
--------------------------------------------------------------------------------
/doc/allclasses-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/doc/allclasses-noframe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | All Classes
7 |
8 |
9 |
10 |
11 |
12 | All Classes
13 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/ArrivalTime.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.ArrivalTime
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
91 |
92 |
93 |
113 |
114 |
115 |
116 |
117 |
135 |
136 |
137 | Prev
138 | Next
139 |
140 |
144 |
147 |
148 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/BusDatabase.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.BusDatabase
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
91 |
92 |
93 |
113 |
114 |
115 |
116 |
117 |
135 |
136 |
137 | Prev
138 | Next
139 |
140 |
144 |
147 |
148 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/KmbApi.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.KmbApi
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.github.mob41.kmbeta.api.KmbApi
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/MultiArrivalManager.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.MultiArrivalManager
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.github.mob41.kmbeta.api.MultiArrivalManager
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/ServerTime.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.ServerTime
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
91 |
92 |
93 |
113 |
114 |
115 |
116 |
117 |
135 |
136 |
137 | Prev
138 | Next
139 |
140 |
144 |
147 |
148 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/class-use/Test.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.api.Test
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.github.mob41.kmbeta.api.Test
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.github.mob41.kmbeta.api
7 |
8 |
9 |
10 |
11 |
12 |
13 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.github.mob41.kmbeta.api
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
79 | Class Summary
80 |
81 | Class
82 | Description
83 |
84 |
85 |
86 | ArrivalManager
87 |
88 |
89 |
90 | ArrivalTime
91 |
92 |
93 |
94 | BusDatabase
95 |
96 |
97 |
98 | BusStop
99 |
100 |
101 |
102 | KmbApi
103 | Deprecated
104 |
105 |
106 | MultiArrivalManager
107 |
108 |
109 |
110 | Route
111 |
112 | A class representing a route in the database
113 |
114 |
115 |
116 | RouteBound
117 |
118 | A class representing a bound in the database
119 |
120 |
121 |
122 | ServerTime
123 |
124 | A class for separating server time fetched from KMB ETA Server.
125 |
126 |
127 |
128 | Test
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
155 |
182 |
183 |
184 |
185 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.github.mob41.kmbeta.api Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
79 |
80 |
Class Hierarchy
81 |
82 | java.lang.Object
83 |
95 |
96 |
97 |
98 |
99 |
117 |
118 |
119 | Prev
120 | Next
121 |
122 |
126 |
129 |
130 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/api/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Package com.github.mob41.kmbeta.api
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
91 |
92 |
93 |
94 |
95 |
130 |
131 |
132 |
133 |
134 |
152 |
153 |
154 | Prev
155 | Next
156 |
157 |
161 |
164 |
165 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/exception/class-use/FetchRoutesException.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.exception.FetchRoutesException
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.github.mob41.kmbeta.exception.FetchRoutesException
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/exception/class-use/NoETADataFetchedError.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.github.mob41.kmbeta.exception.NoETADataFetchedError
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 | Methods in com.github.mob41.kmbeta.api that throw NoETADataFetchedError
100 |
101 | Modifier and Type
102 | Method and Description
103 |
104 |
105 |
106 | java.lang.String
107 | ArrivalManager. getArrivalTimeText ()
108 | Returns a formatted arrival time text.
109 |
110 | The arrival time is formatted to: HH:MM
111 | If hour/minute is less than 10
, a 0
will be added to the front.
112 | If the received response is equal to the last departed message, it will return "End"
.
113 | If the received response is invalid, it will return "Invalid"
.
114 | If no response received, it will probably return "NoData"
or "Failed"
.
115 | If the separation of Hour and Minutes failed, it will return the raw arrival time.
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
144 |
145 |
146 | Prev
147 | Next
148 |
149 |
153 |
156 |
157 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/exception/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.github.mob41.kmbeta.exception
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Exceptions
15 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/doc/com/github/mob41/kmbeta/exception/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.github.mob41.kmbeta.exception Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
79 |
80 |
Class Hierarchy
81 |
82 | java.lang.Object
83 |
84 | java.lang.Throwable (implements java.io.Serializable)
85 |
86 | java.lang.Exception
87 |
88 | java.lang.RuntimeException
89 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
130 |
157 |
158 |
159 |
160 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/class-use/Get2ABusArrival.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.mob41.kmbeta.api.tests.Get2ABusArrival
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.mob41.kmbeta.api.tests.Get2ABusArrival
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/class-use/MultiArrivals.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Class com.mob41.kmbeta.api.tests.MultiArrivals
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.mob41.kmbeta.api.tests.MultiArrivals
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/package-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.mob41.kmbeta.api.tests
7 |
8 |
9 |
10 |
11 |
12 |
13 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/package-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.mob41.kmbeta.api.tests
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 |
76 |
77 |
78 |
79 | Class Summary
80 |
81 | Class
82 | Description
83 |
84 |
85 |
86 | Get2ABusArrival
87 |
88 |
89 |
90 | MultiArrivals
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
117 |
144 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/package-tree.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | com.mob41.kmbeta.api.tests Class Hierarchy
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
79 |
80 |
Class Hierarchy
81 |
82 | java.lang.Object
83 |
87 |
88 |
89 |
90 |
91 |
109 |
110 |
111 | Prev
112 | Next
113 |
114 |
118 |
121 |
122 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/doc/com/mob41/kmbeta/api/tests/package-use.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Uses of Package com.mob41.kmbeta.api.tests
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
75 | No usage of com.mob41.kmbeta.api.tests
76 |
77 |
95 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/doc/deprecated-list.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Deprecated List
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
80 |
81 |
82 |
83 |
98 |
99 |
100 |
101 |
122 |
123 |
124 |
142 |
143 |
144 | Prev
145 | Next
146 |
147 |
151 |
154 |
155 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
--------------------------------------------------------------------------------
/doc/index-files/index-11.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | M-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
M
76 |
77 | main(String[]) - Static method in class com.github.mob41.kmbeta.api.Test
78 |
79 | MultiArrivalManager - Class in com.github.mob41.kmbeta.api
80 |
81 | MultiArrivalManager(int) - Constructor for class com.github.mob41.kmbeta.api.MultiArrivalManager
82 |
83 | MultiArrivals - Class in com.mob41.kmbeta.api.tests
84 |
85 | MultiArrivals() - Constructor for class com.mob41.kmbeta.api.tests.MultiArrivals
86 |
87 |
88 |
A B C D E F G I K L M N R S T U
89 |
90 |
108 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/doc/index-files/index-13.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | R-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
R
76 |
77 | removeArrivalManager(int) - Method in class com.github.mob41.kmbeta.api.MultiArrivalManager
78 |
79 | Route - Class in com.github.mob41.kmbeta.api
80 |
81 | A class representing a route in the database
82 |
83 | RouteBound - Class in com.github.mob41.kmbeta.api
84 |
85 | A class representing a bound in the database
86 |
87 |
88 |
A B C D E F G I K L M N R S T U
89 |
90 |
108 |
135 |
136 |
137 |
138 |
--------------------------------------------------------------------------------
/doc/index-files/index-14.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | S-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
S
76 |
77 | ServerTime - Class in com.github.mob41.kmbeta.api
78 |
79 | A class for separating server time fetched from KMB ETA Server.
80 |
81 | ServerTime(String) - Constructor for class com.github.mob41.kmbeta.api.ServerTime
82 |
83 | ServerTime() - Constructor for class com.github.mob41.kmbeta.api.ServerTime
84 |
85 | setTargetIndex(int) - Method in class com.github.mob41.kmbeta.api.ArrivalTime
86 |
87 | Sets the target index.
88 |
89 |
90 |
A B C D E F G I K L M N R S T U
91 |
92 |
110 |
137 |
138 |
139 |
140 |
--------------------------------------------------------------------------------
/doc/index-files/index-15.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | T-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
T
76 |
77 | Test - Class in com.github.mob41.kmbeta.api
78 |
79 | Test() - Constructor for class com.github.mob41.kmbeta.api.Test
80 |
81 | test() - Method in class com.mob41.kmbeta.api.tests.Get2ABusArrival
82 |
83 | test() - Method in class com.mob41.kmbeta.api.tests.MultiArrivals
84 |
85 |
86 |
A B C D E F G I K L M N R S T U
87 |
88 |
106 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/doc/index-files/index-16.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | U-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
U
76 |
77 | unloadDatabase() - Method in class com.github.mob41.kmbeta.api.BusDatabase
78 |
79 | Unloads the database.
80 |
81 |
82 |
A B C D E F G I K L M N R S T U
83 |
84 |
102 |
129 |
130 |
131 |
132 |
--------------------------------------------------------------------------------
/doc/index-files/index-2.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | B-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
B
76 |
77 | bus_db - Static variable in class com.github.mob41.kmbeta.api.KmbApi
78 |
79 | Deprecated.
80 |
81 | BusDatabase - Class in com.github.mob41.kmbeta.api
82 |
83 | BusStop - Class in com.github.mob41.kmbeta.api
84 |
85 |
86 |
A B C D E F G I K L M N R S T U
87 |
88 |
106 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/doc/index-files/index-5.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | E-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
E
76 |
77 | ENGLISH_LANG - Static variable in class com.github.mob41.kmbeta.api.ArrivalManager
78 |
79 | ENGLISH_LANG - Static variable in class com.github.mob41.kmbeta.api.KmbApi
80 |
81 | Deprecated.
82 |
83 | ETA_DATAFEED_SERVER_URL - Static variable in class com.github.mob41.kmbeta.api.ArrivalManager
84 |
85 | ETA_SERVER_URL - Static variable in class com.github.mob41.kmbeta.api.ArrivalManager
86 |
87 | etadatafeed - Static variable in class com.github.mob41.kmbeta.api.KmbApi
88 |
89 | Deprecated.
90 |
91 | etaserver - Static variable in class com.github.mob41.kmbeta.api.KmbApi
92 |
93 | Deprecated.
94 |
95 |
96 |
A B C D E F G I K L M N R S T U
97 |
98 |
116 |
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/doc/index-files/index-9.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | K-Index
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 | A B C D E F G I K L M N R S T U
73 |
74 |
75 |
K
76 |
77 | KmbApi - Class in com.github.mob41.kmbeta.api
78 |
79 | Deprecated.
80 |
81 | KmbApi() - Constructor for class com.github.mob41.kmbeta.api.KmbApi
82 |
83 | Deprecated.
84 |
85 |
86 |
A B C D E F G I K L M N R S T U
87 |
88 |
106 |
133 |
134 |
135 |
136 |
--------------------------------------------------------------------------------
/doc/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Generated Documentation (Untitled)
7 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | JavaScript is disabled on your browser.
69 |
70 | Frame Alert
71 | This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version .
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/doc/overview-frame.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Overview List
7 |
8 |
9 |
10 |
11 |
12 |
13 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/doc/overview-summary.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Overview
7 |
8 |
9 |
10 |
11 |
12 |
22 |
23 | JavaScript is disabled on your browser.
24 |
25 |
26 |
44 |
71 |
72 |
95 |
96 |
114 |
115 |
116 | Prev
117 | Next
118 |
119 |
123 |
126 |
127 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
--------------------------------------------------------------------------------
/doc/package-list:
--------------------------------------------------------------------------------
1 | com.github.mob41.kmbeta.api
2 | com.github.mob41.kmbeta.exception
3 | com.mob41.kmbeta.api.tests
4 |
--------------------------------------------------------------------------------
/doc/script.js:
--------------------------------------------------------------------------------
1 | function show(type)
2 | {
3 | count = 0;
4 | for (var key in methods) {
5 | var row = document.getElementById(key);
6 | if ((methods[key] & type) != 0) {
7 | row.style.display = '';
8 | row.className = (count++ % 2) ? rowColor : altColor;
9 | }
10 | else
11 | row.style.display = 'none';
12 | }
13 | updateTabs(type);
14 | }
15 |
16 | function updateTabs(type)
17 | {
18 | for (var value in tabs) {
19 | var sNode = document.getElementById(tabs[value][0]);
20 | var spanNode = sNode.firstChild;
21 | if (value == type) {
22 | sNode.className = activeTableTab;
23 | spanNode.innerHTML = tabs[value][1];
24 | }
25 | else {
26 | sNode.className = tableTab;
27 | spanNode.innerHTML = "" + tabs[value][1] + " ";
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 | com.github.mob41.kmbeta
4 | KmbETA-API
5 | 1.5.0-SNAPSHOT
6 | KmbETA-API
7 | An API client getting ETA from KMB buses.
8 |
9 |
10 | org.json
11 | json
12 | 20160212
13 |
14 |
15 | junit
16 | junit
17 | 4.12
18 |
19 |
20 | commons-codec
21 | commons-codec
22 | 1.10
23 |
24 |
25 |
26 |
27 |
28 | maven-surefire-plugin
29 | 2.10
30 |
31 | false
32 |
33 |
34 |
35 | maven-assembly-plugin
36 |
37 |
38 | package
39 |
40 | single
41 |
42 |
43 |
44 |
45 |
46 | jar-with-dependencies
47 |
48 |
49 |
50 |
51 | org.apache.maven.plugins
52 | maven-javadoc-plugin
53 |
54 |
55 | attach-javadocs
56 |
57 | jar
58 |
59 |
60 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/ArrivalTime.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | import org.json.JSONException;
4 | import org.json.JSONObject;
5 |
6 | public class ArrivalTime {
7 |
8 | private static final String lastdeparted_msg = ArrivalManager.lastdeparted_msg;
9 |
10 | private JSONObject etadata = null;
11 |
12 | private String raw_time = null;
13 |
14 | private int index = -1;
15 |
16 | public ArrivalTime(JSONObject etadata) throws JSONException{
17 | this(etadata, 0);
18 | }
19 |
20 | public ArrivalTime(JSONObject etadata, int index) throws JSONException{
21 | if (etadata == null){
22 | this.raw_time = "Failed";
23 | } else if (etadata.isNull("response")){
24 | this.raw_time = "NoData";
25 | } else {
26 | String output = (String) etadata.getJSONArray("response").getJSONObject(index).get("t");
27 | this.raw_time = output;
28 | }
29 | this.etadata = etadata;
30 | this.index = index;
31 | }
32 |
33 | /**
34 | * Gets the pure/untouched JSON passed to this instance.
35 | * @return the pure/untouched JSONObject
response
36 | */
37 | public JSONObject getRawJSON(){
38 | return etadata;
39 | }
40 |
41 | /**
42 | * Sets the target index. The response contains multiple estimated arrival time data.
43 | *
44 | * By default, the first one is selected.
45 | * @param index
46 | */
47 | public void setTargetIndex(int index){
48 | String output = (String) etadata.getJSONArray("response").getJSONObject(index).get("t");
49 |
50 | this.raw_time = output;
51 | this.index = index;
52 | }
53 |
54 | /***
55 | * Get the arrival time (Hour Part)
56 | * @return
57 | * Returns -1 if arrival time is null
.
58 | * Returns -2 if the fetched time is not an integer.
59 | * Returns -3 if last departed.
60 | */
61 | public int getArrivalHour(){
62 | if (raw_time == null){
63 | return 1;
64 | }
65 | if (raw_time.equals(lastdeparted_msg)){
66 | return -3;
67 | }
68 | String preoutput;
69 | int output;
70 | preoutput = raw_time.substring(0, 2);
71 | try {
72 | output = Integer.parseInt(preoutput);
73 | } catch (NumberFormatException e){
74 | output = -2;
75 | }
76 | return output;
77 | }
78 |
79 | /***
80 | * Get the arrival time (Minute Part)
81 | * @return
82 | * Returns -1 if arrival time is null
.
83 | * Returns -2 if the fetched time is not an integer.
84 | * Returns -3 if last departed.
85 | */
86 | public int getArrivalMin(){
87 | if (raw_time == null){
88 | return 1;
89 | }
90 | if (raw_time.equals(lastdeparted_msg)){
91 | return -3;
92 | }
93 | String preoutput;
94 | int output;
95 | preoutput = raw_time.substring(3, 5);
96 | try {
97 | output = Integer.parseInt(preoutput);
98 | } catch (NumberFormatException e){
99 | output = -2;
100 | }
101 | return output;
102 | }
103 |
104 | /***
105 | * Returns whether the specified arrival time is a scheduled time.
106 | * @param i The index of arrival times. See the KMB App for details.
107 | * @return Boolean
108 | */
109 | public boolean isScheTime(int i){
110 | if (etadata == null){
111 | return true;
112 | }
113 | System.out.println(etadata);
114 | String isScheTimeString = (String) etadata.getJSONArray("response").getJSONObject(i).get("ei");
115 | System.out.println(isScheTimeString);
116 | return isScheTimeString.equals("Y");
117 | }
118 |
119 | /***
120 | * Returns whether the selected index
arrival time is a scheduled time.
121 | * @return Boolean
122 | */
123 | public boolean isScheTime(){
124 | return isScheTime(index);
125 | }
126 |
127 | /**
128 | * Get the raw fetched arrival time
129 | * @return Raw String Data
130 | */
131 | public String getRawArrivalTime(){
132 | return raw_time;
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/BusStop.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | public class BusStop {
4 |
5 | /**
6 | * Linked route
7 | */
8 | private final Route route;
9 |
10 | /**
11 | * Linked route bound
12 | */
13 | private final RouteBound routeBound;
14 |
15 | /**
16 | * This route bound index
17 | */
18 | private final int bound;
19 |
20 | /**
21 | * This bus stop's latitude
22 | */
23 | private final double lat;
24 |
25 | /**
26 | * This bus stop's longitude
27 | */
28 | private final double lng;
29 |
30 | /**
31 | * This bus stop's location (Area)
32 | */
33 | private final String area;
34 |
35 | /**
36 | * This stop code (Sub-area)
37 | */
38 | private final String stopcode;
39 |
40 | /**
41 | * This stop name in English
42 | */
43 | private final String stopname_eng;
44 |
45 | /**
46 | * This stop name in Chinese
47 | */
48 | private final String stopname_chi;
49 |
50 | /**
51 | * This stop's address in English
52 | */
53 | private final String addr_eng;
54 |
55 | /**
56 | * This stop's address in Chinese
57 | */
58 | private final String addr_chi;
59 |
60 | /**
61 | * This stop's normal fare (No longer exist now)
62 | */
63 | private final double normal_fare;
64 |
65 | /**
66 | * This stop's air conditioner fare (Normal fare)
67 | */
68 | private final double air_cond_fare;
69 |
70 | /**
71 | * This stop sequence
72 | */
73 | private final int stop_seq;
74 |
75 | /**
76 | * Creates a new BusStop instance, representing a bus stop in the database
77 | *
78 | * It is restricted to create a BusStop instance out of the package
79 | * @param linkedRoute The linked route
80 | * @param linkedBound The linked route bound
81 | * @param bound This route bound
82 | * @param lat This stop's latitude
83 | * @param lng This stop's longitude
84 | * @param area This stop's location (Area)
85 | * @param stopcode This stop code
86 | * @param stopname_eng This stop name in English
87 | * @param stopname_chi This stop name in Chinese
88 | * @param addr_eng This stop's address in English
89 | * @param addr_chi This stop's address in Chinese
90 | * @param normal_fare This stop's normal fare/no air-con (No longer exist now)
91 | * @param air_cond_fare This stop's air-conditioner fare (Normal fare by now)
92 | * @param stop_seq This stop sequence
93 | */
94 | protected BusStop(Route linkedRoute, RouteBound linkedBound, int bound, double lat, double lng,
95 | String area, String stopcode, String stopname_eng, String stopname_chi, String addr_eng,
96 | String addr_chi, double normal_fare, double air_cond_fare, int stop_seq){
97 | this.route = linkedRoute;
98 | this.routeBound = linkedBound;
99 | this.bound = bound;
100 | this.lat = lat;
101 | this.lng = lng;
102 | this.area = area;
103 | this.stopcode = stopcode;
104 | this.stopname_eng = stopname_eng;
105 | this.stopname_chi = stopname_chi;
106 | this.addr_eng = addr_eng;
107 | this.addr_chi = addr_chi;
108 | this.normal_fare = normal_fare;
109 | this.air_cond_fare = air_cond_fare;
110 | this.stop_seq = stop_seq;
111 | }
112 |
113 | /**
114 | * Gets the linked route
115 | * @return The Route instance
116 | */
117 | public Route getRoute(){
118 | return route;
119 | }
120 |
121 | /**
122 | * Gets the linked route bound
123 | * @return The RouteBound instance
124 | */
125 | public RouteBound getBound(){
126 | return routeBound;
127 | }
128 |
129 | /**
130 | * Gets this linked route bound's index in the route
131 | * @return The route bound's index in the route
132 | */
133 | public int getBoundIndex(){
134 | return bound;
135 | }
136 |
137 | /**
138 | * Gets this stop's latitude
139 | * @return This stop's latitude
140 | */
141 | public double getLatitude(){
142 | return lat;
143 | }
144 |
145 | /**
146 | * Gets this stop's longitude
147 | * @return This stop's longitude
148 | */
149 | public double getLongitude(){
150 | return lng;
151 | }
152 |
153 | /**
154 | * Gets this stop's area
155 | * @return This stop's area
156 | */
157 | public String getArea(){
158 | return area;
159 | }
160 |
161 | /**
162 | * Gets this stop code
163 | * @return This stop code in String
164 | */
165 | public String getStopCode(){
166 | return stopcode;
167 | }
168 |
169 | /**
170 | * Gets the stop name in English
171 | * @return Stop name in English in String
172 | */
173 | public String getStopNameInEnglish(){
174 | return stopname_eng;
175 | }
176 |
177 | /**
178 | * Gets the stop name in Chinese
179 | * @return Stop name in Chinese in String
180 | */
181 | public String getStopNameInChinese(){
182 | return stopname_chi;
183 | }
184 |
185 | /**
186 | * Gets the address of this stop in English
187 | * @return The address in English
188 | */
189 | public String getAddressInEnglish(){
190 | return addr_eng;
191 | }
192 |
193 | /**
194 | * Gets the address of this stop in Chinese
195 | * @return The address in Chinese
196 | */
197 | public String getAddressInChinese(){
198 | return addr_chi;
199 | }
200 |
201 | /**
202 | * @deprecated
203 | * There is no more "No Air-con" buses in Hong Kong
204 | * It will return 0.0
usually
205 | * Use getAirCondFare()
instead.
206 | *
207 | * Gets the normal/No air-con fare (No longer exist now)
208 | * @return Normal/No air-con fare of this stop
209 | */
210 | public double getNormalFare(){
211 | return normal_fare;
212 | }
213 |
214 | /**
215 | * Gets the air-conditioner fare of this stop, instead of normal fare
216 | * @return Air-conditioner fare of this stop
217 | */
218 | public double getAirCondFare(){
219 | return air_cond_fare;
220 | }
221 |
222 | /**
223 | * Gets the stop sequence
224 | * @return Stop sequence
225 | */
226 | public int getStopSeq(){
227 | return stop_seq;
228 | }
229 | }
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/MultiArrivalManager.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | public class MultiArrivalManager {
7 |
8 | private List multiman = null;
9 |
10 | public MultiArrivalManager(int multiples){
11 | multiman = new ArrayList(multiples);
12 | }
13 |
14 | public void addArrivalManager(ArrivalManager man){
15 | multiman.add(man);
16 | }
17 |
18 | public void removeArrivalManager(int index){
19 | multiman.remove(index);
20 | }
21 |
22 | public List getArrivalManagers(){
23 | return multiman;
24 | }
25 |
26 | public void fetchAllData(){
27 | for (int i = 0; i < multiman.size(); i++){
28 | ArrivalManager man = multiman.get(i);
29 | man.fetchNewData();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/Route.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * A class representing a route in the database
8 | * @author Anthony
9 | *
10 | */
11 | public class Route {
12 |
13 | /**
14 | * Default maximum bounds of a route
15 | */
16 | public static final int DEFAULT_MAXIMUM_BOUNDS = 2;
17 |
18 | /**
19 | * This route's name
20 | */
21 | private final String routeName;
22 |
23 | /**
24 | * Stores bounds of this route
25 | */
26 | private final List bounds;
27 |
28 | /**
29 | * Creates a new Route instance, representing a route in the database.
30 | *
31 | * It is restricted to create a instance out of this package.
32 | * @param routeName This route's name
33 | */
34 | protected Route(String routeName){
35 | this.routeName = routeName;
36 | bounds = new ArrayList(DEFAULT_MAXIMUM_BOUNDS);
37 | }
38 |
39 | /**
40 | * Adds a new route bound to this route.
41 | * @param bound The instance of RouteBound
42 | */
43 | protected void addBound(RouteBound bound){
44 | bounds.add(bound);
45 | }
46 |
47 | /**
48 | * Removes a route bound from this route by index
49 | * @param index The index of the bound in the list
50 | */
51 | protected void removeBound(int index){
52 | bounds.remove(bounds);
53 | }
54 |
55 | /**
56 | * Removes a route bound from this route by the instance
57 | * @param bound The instance of RouteBound
58 | */
59 | protected void removeBound(RouteBound bound){
60 | bounds.remove(bound);
61 | }
62 |
63 | /**
64 | * Gets the route bound list in the route.
65 | * @return The list of RouteBound instances
66 | */
67 | public List getList(){
68 | return bounds;
69 | }
70 |
71 | /**
72 | * Gets the name of this route
73 | * @return A string
74 | */
75 | public String getName(){
76 | return routeName;
77 | }
78 |
79 | /**
80 | * Gets a RouteBound
from the route.
81 | * @param index The index of the RouteBound in the list. Probably 0
or 1
82 | * @return The route bound instance. If not exist, returns null
83 | */
84 | public RouteBound getBound(int index){
85 | return bounds.get(index);
86 | }
87 |
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/RouteBound.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * A class representing a bound in the database
8 | * @author Anthony
9 | *
10 | */
11 | public class RouteBound {
12 |
13 | /**
14 | * Default maximum bus stops
15 | */
16 | public static final int DEFAULT_MAXIMUM_STOPS = 200;
17 |
18 | /**
19 | * Stores the route that linked to this bound
20 | */
21 | private final Route route;
22 |
23 | /**
24 | * Stores the stops in this bound
25 | */
26 | private final List stops;
27 |
28 | /**
29 | * Creates a new route bound instance
30 | *
31 | * It is restricted to create a route bound instance out of this package
32 | * @param route The route that linked to this bound
33 | */
34 | protected RouteBound(Route route){
35 | stops = new ArrayList(200);
36 | this.route = route;
37 | }
38 |
39 | /**
40 | * Adds a bus stop instance to this route
41 | * @param stop The bus stop instance to be added
42 | */
43 | protected void addStop(BusStop stop){
44 | stops.add(stop);
45 | }
46 |
47 | /**
48 | * Removes a bus stop instance to this route by instance
49 | * @param stop The isntance to be searched
50 | */
51 | protected void removeStop(BusStop stop){
52 | stops.remove(stop);
53 | }
54 |
55 | /**
56 | * Removes a bus stop instance to this route by index
57 | * @param index The index of the list
58 | */
59 | protected void removeStop(int index){
60 | stops.remove(index);
61 | }
62 |
63 | /**
64 | * Gets the bus stop instance in the list by index
65 | * @param index The index of the instance in the list
66 | * @return The bus stop instance
67 | */
68 | public BusStop getBusStop(int index){
69 | return stops.get(index);
70 | }
71 |
72 | /**
73 | * Gets the list of bus stops
74 | * @return A List
instance containing bus stops
75 | */
76 | public List getList(){
77 | return stops;
78 | }
79 |
80 | /**
81 | * Gets the route linked to this bound
82 | * @return Route linked
83 | */
84 | public Route getRoute(){
85 | return route;
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/ServerTime.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.InputStreamReader;
5 | import java.net.URL;
6 | import java.net.URLConnection;
7 |
8 | import org.json.JSONArray;
9 |
10 | /**
11 | * A class for separating server time fetched from KMB ETA Server.
12 | *
13 | * This class is probably useless for API users.
14 | * @author Anthony
15 | *
16 | */
17 | public class ServerTime {
18 |
19 | private String serverTime = null;
20 |
21 | public ServerTime(String serverTime){
22 | this.serverTime = serverTime;
23 | }
24 |
25 | public ServerTime(){
26 | this.serverTime = getServerTime();
27 | }
28 |
29 | /***
30 | * Get Server Time (Hour Part)
31 | *
32 | * @return Integer, returns -1 if serverTime
is null
33 | */
34 | public int getServerHour(){
35 | if (serverTime == null){
36 | return -1;
37 | }
38 | int hour = Integer.parseInt(serverTime.substring(11, 13));
39 | return hour;
40 | }
41 |
42 | /***
43 | * Get Server Time (Minute Part)
44 | *
45 | * @return Integer, returns -1 if serverTime
is null
46 | */
47 | public int getServerMin(){
48 | if (serverTime == null){
49 | return -1;
50 | }
51 | int min = Integer.parseInt(serverTime.substring(14, 16));
52 | return min;
53 | }
54 |
55 | /***
56 | * Get Server Time (Seconds Part)
57 | *
58 | * @return Integer, returns -1 if serverTime
is null
59 | */
60 | public int getServerSec(){
61 | if (serverTime == null){
62 | return -1;
63 | }
64 |
65 | int sec = Integer.parseInt(serverTime.substring(16, 18));
66 | return sec;
67 | }
68 |
69 | /**
70 | * Get the Whole Server Time (e.g. 15:30:00)
71 | *
72 | * @return String
73 | */
74 | public String getWholeTime(){
75 | return getServerHour() + ":" + getServerMin() + ":" + getServerSec();
76 | }
77 |
78 | /**
79 | * Get the raw fetched server time (e.g. 2016-04-18 19:29:06)
80 | *
81 | * @return String
82 | */
83 | public String getRawServerTime(){
84 | return serverTime;
85 | }
86 |
87 | //Static functions
88 |
89 | /***
90 | * Get KMB data feed server time. And save to memory for other functions
91 | *
92 | * Must be called before any arrival calculating events.
93 | *
94 | * e.g. 23:45:33
95 | * @return String
96 | */
97 | public static String getServerTime(){
98 | try {
99 | String datafeedurl = ArrivalManager.ETA_DATAFEED_SERVER_URL + "GetData.ashx?type=Server_T";
100 | System.out.println(datafeedurl);
101 |
102 | URL url = new URL(datafeedurl);
103 |
104 | URLConnection connection = url.openConnection();
105 | String line;
106 |
107 | StringBuilder builder = new StringBuilder();
108 | BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
109 | while((line = reader.readLine()) != null) {
110 | builder.append(line);
111 | }
112 |
113 | JSONArray kmbJson = new JSONArray(builder.toString());
114 |
115 | System.out.println(kmbJson.toString());
116 | String datetime = (String) kmbJson.getJSONObject(0).get("stime");
117 |
118 | System.out.println(datetime);
119 | return datetime;
120 | } catch (Exception e){
121 | e.printStackTrace();
122 | return null;
123 | }
124 | }
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/api/Test.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.api;
2 |
3 | public class Test {
4 |
5 | public static void main(String[] args){
6 |
7 | }
8 |
9 | }
10 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/CouldNotLoadDatabaseException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * Could not load the ETA database
5 | * @author mob41
6 | *
7 | */
8 | public class CouldNotLoadDatabaseException extends RuntimeException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public CouldNotLoadDatabaseException(){
16 | super();
17 | }
18 |
19 | public CouldNotLoadDatabaseException(String message){
20 | super(message);
21 | }
22 |
23 | public CouldNotLoadDatabaseException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public CouldNotLoadDatabaseException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/DatabaseNotLoadedException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * ETA database not loaded exception.
5 | * @author mob41
6 | *
7 | */
8 | public class DatabaseNotLoadedException extends RuntimeException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public DatabaseNotLoadedException(){
16 | super("The static database wasn't loaded at the moment.");
17 | }
18 |
19 | public DatabaseNotLoadedException(String message){
20 | super(message);
21 | }
22 |
23 | public DatabaseNotLoadedException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public DatabaseNotLoadedException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/FetchRoutesException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * ETA database not loaded exception.
5 | * @author mob41
6 | *
7 | */
8 | public class FetchRoutesException extends RuntimeException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public FetchRoutesException(){
16 | super("The static database wasn't loaded at the moment.");
17 | }
18 |
19 | public FetchRoutesException(String message){
20 | super(message);
21 | }
22 |
23 | public FetchRoutesException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public FetchRoutesException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/InvalidArrivalTargetException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * The specified Bus No. was invalid.
5 | * @author mob41
6 | *
7 | */
8 | public class InvalidArrivalTargetException extends InvalidException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public InvalidArrivalTargetException(){
16 | super();
17 | }
18 |
19 | public InvalidArrivalTargetException(String message){
20 | super(message);
21 | }
22 |
23 | public InvalidArrivalTargetException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public InvalidArrivalTargetException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/InvalidException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * The base class of all Invalid Exception
5 | * @author mob41
6 | *
7 | */
8 | public class InvalidException extends RuntimeException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public InvalidException(){
16 | super();
17 | }
18 |
19 | public InvalidException(String message){
20 | super(message);
21 | }
22 |
23 | public InvalidException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public InvalidException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/NoETADataFetchedError.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * The ETA Data wasn't fetched before. It kept null
.
5 | * @author mob41
6 | *
7 | */
8 | public class NoETADataFetchedError extends InvalidException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public NoETADataFetchedError(){
16 | super();
17 | }
18 |
19 | public NoETADataFetchedError(String message){
20 | super(message);
21 | }
22 |
23 | public NoETADataFetchedError(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public NoETADataFetchedError(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/NoServerTimeFetchedError.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * The Server Time wasn't fetched before. It kept null
.
5 | * @author mob41
6 | *
7 | */
8 | public class NoServerTimeFetchedError extends InvalidException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public NoServerTimeFetchedError(){
16 | super();
17 | }
18 |
19 | public NoServerTimeFetchedError(String message){
20 | super(message);
21 | }
22 |
23 | public NoServerTimeFetchedError(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public NoServerTimeFetchedError(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/com/github/mob41/kmbeta/exception/NoSuchRouteException.java:
--------------------------------------------------------------------------------
1 | package com.github.mob41.kmbeta.exception;
2 |
3 | /***
4 | * ETA database not loaded exception.
5 | * @author mob41
6 | *
7 | */
8 | public class NoSuchRouteException extends RuntimeException {
9 |
10 | /**
11 | *
12 | */
13 | private static final long serialVersionUID = 1L;
14 |
15 | public NoSuchRouteException(){
16 | super();
17 | }
18 |
19 | public NoSuchRouteException(String message){
20 | super(message);
21 | }
22 |
23 | public NoSuchRouteException(String message, Throwable cause){
24 | super(message, cause);
25 | }
26 |
27 | public NoSuchRouteException(Throwable cause){
28 | super(cause);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/test/java/com/mob41/kmbeta/api/tests/Get2ABusArrival.java:
--------------------------------------------------------------------------------
1 | package com.mob41.kmbeta.api.tests;
2 |
3 | import org.junit.Test;
4 |
5 | import com.github.mob41.kmbeta.api.ArrivalManager;
6 | import com.github.mob41.kmbeta.exception.CouldNotLoadDatabaseException;
7 | import com.github.mob41.kmbeta.exception.InvalidArrivalTargetException;
8 |
9 | public class Get2ABusArrival {
10 |
11 | @Test
12 | public void test() throws InvalidArrivalTargetException, CouldNotLoadDatabaseException{
13 | final String busno = "2A";
14 | final String stopcode = "LO02T10000";
15 | final String stopname = "LOK WAH BUS TERMINUS";
16 | final int bound = 1;
17 | ArrivalManager arr = new ArrivalManager(busno, stopcode, bound, ArrivalManager.ENGLISH_LANG, false);
18 | arr.fetchNewData(); //This also run getServerTime()
19 | System.out.println("Arrival status at " + stopname + " is " + arr.getRemainingArrivalMinuteText());
20 | System.out.println("Stopname: " + stopname);
21 | System.out.println("Stopcode:" + stopcode);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/test/java/com/mob41/kmbeta/api/tests/MultiArrivals.java:
--------------------------------------------------------------------------------
1 | package com.mob41.kmbeta.api.tests;
2 |
3 | import org.junit.Test;
4 |
5 | import com.github.mob41.kmbeta.api.ArrivalManager;
6 | import com.github.mob41.kmbeta.api.MultiArrivalManager;
7 | import com.github.mob41.kmbeta.exception.CouldNotLoadDatabaseException;
8 | import com.github.mob41.kmbeta.exception.InvalidArrivalTargetException;
9 |
10 | public class MultiArrivals {
11 |
12 | @Test
13 | public void test() throws InvalidArrivalTargetException, CouldNotLoadDatabaseException{
14 | MultiArrivalManager mularr = new MultiArrivalManager(50);
15 | ArrivalManager arr0 = new ArrivalManager("1A", "SA06T10000", 1, ArrivalManager.ENGLISH_LANG, false); //SAU MAU PING (CENTRAL)
16 | ArrivalManager arr1 = new ArrivalManager("1", "CH15T11000", 1, ArrivalManager.ENGLISH_LANG, false); //CHUK YUEN EST. BUS TERMINUS
17 | mularr.addArrivalManager(arr0);
18 | mularr.addArrivalManager(arr1);
19 |
20 | mularr.fetchAllData(); //Request all manager to fetch data (This also run getServerTime)
21 |
22 | for (int i = 0; i < 2; i++){
23 | ArrivalManager man = mularr.getArrivalManagers().get(i);
24 | System.out.println("Arr" + i + " BusNo: " + man.getBusNo());
25 | System.out.println("Arr" + i + " Bound: " + man.getBound());
26 | System.out.println("Arr" + i + " StopCode: " + man.getStopCode());
27 | System.out.println("Arr" + i + " StopSeq: " + man.getStopSeq());
28 | System.out.println("Arr" + i + ": " + man.getRemainingArrivalMinuteText());
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------