Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package cz.fhejl.pubtran;
- import java.io.Serializable;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Locale;
- import cz.fhejl.pubtran.Departures.Platform;
- import cz.fhejl.pubtran.JourneyPart.TransportType;
- import cz.fhejl.pubtran.api.TtwsSoapParser.Elem;
- import cz.fhejl.pubtran.other.TimeUtils;
- @SuppressWarnings("serial")
- public class Departures extends ArrayList<Platform> {
- public Departures(Elem root) {
- for (Elem elem : root.getElems("aoInfo")) {
- int platformId = elem.getElem("oStation1").getInt("iStation");
- String platformName = elem.getElem("oStation1").getString("sName");
- Platform platform = new Platform(platformName, platformId);
- for (int i = 0; i <= size(); i++) {
- if (i == size() || get(i).getId() > platformId) {
- add(i, platform);
- break;
- } else if (get(i).getId() == platformId) {
- platform = get(i);
- break;
- }
- }
- String time = elem.getString("dtDateTime1");
- String symbol = elem.getElem("oTrain").getString("sNum1");
- String name = elem.getElem("oTrain").getString("sNum2");
- String type = elem.getElem("oTrain").getString("sType");
- TransportType transportType = TransportType.find(elem.getElem("oTrain").getInt("iID"));
- String destination = elem.getElem("oStationTrainEnd").getString("sName");
- Departure departure = new Departure(symbol, name, type, transportType, time, destination);
- platform.getDepartures().add(departure);
- }
- }
- private static long parseDateTime(String s) {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.US);
- sdf.setTimeZone(TimeUtils.getCzechTimezone());
- Date date = null;
- try {
- date = sdf.parse(s);
- } catch (java.text.ParseException e) {
- e.printStackTrace();
- }
- return date.getTime();
- }
- public static class Platform implements Serializable {
- private int id;
- private ArrayList<Departure> departures = new ArrayList<Departure>();
- private String name;
- public Platform(String name, int id) {
- this.name = name;
- this.id = id;
- }
- public ArrayList<Departure> getDepartures() {
- return departures;
- }
- public int getId() {
- return id;
- }
- public String getName() {
- return name;
- }
- }
- public static class Departure implements Serializable {
- private long time;
- private String name;
- private String destination;
- public Departure(String num1, String num2, String type, TransportType transportType, String time,
- String destination) {
- this.time = parseDateTime(time);
- this.destination = destination;
- name = num1;
- if (transportType == TransportType.TRAIN || num1.length() > 4 || !num2.equals("")) {
- name = type + " " + num1;
- if (num2 != null) name += " " + num2;
- }
- }
- public long getTime() {
- return time;
- }
- public String getName() {
- return name;
- }
- public String getDestination() {
- return destination;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement