Ejemplo n.º 1
0
  public static void main(String[] args) {
    // Varje station har ett ID i form av ett nummer, searchURL stoppar in dessa i XSDn samt hur
    // många resultat som ska visas.
    String searchURL =
        Constants.getURL(
            "80100", "93070",
            20); // Malmö C = 80000,  Lund C, 81216 Malmö Gatorg 80100, Hässleholm C 93070
    System.out.println(searchURL);
    System.out.println("// Results when searching:");

    Journeys journeys =
        Parser.getJourneys(
            searchURL); // använder XSDn genererad av searchURL för att hämta information om resan
    for (Journey journey : journeys.getJourneys()) {
      System.out.print(journey.getStartStation() + " - ");
      System.out.print(journey.getEndStation());
      String time =
          journey.getDepDateTime().get(Calendar.HOUR_OF_DAY)
              + ":"
              + journey.getDepDateTime().get(Calendar.MINUTE);
      System.out.println(
          " Departs "
              + time
              + " that is in "
              + journey.getTimeToDeparture()
              + " minutes. And it is "
              + journey.getDepTimeDeviation()
              + " min late");
    }

    System.out.println("// Stations when searching for stations containing \"Malm\"");
    ArrayList<Station> searchStations =
        new ArrayList<Station>(); // En arraylist som ska innehålla alla malmös stationer
    searchStations.addAll(
        Parser.getStationsFromURL("Malm")); // Hämtar alla stationer som innehåller "Malm"
    for (Station s : searchStations) {
      System.out.println(s.getStationName() + " number:" + s.getStationNbr());
    }

    System.out.println("// Busses departing from Ubåtshallen stationsnummer 80046 ");
    Lines lines = Parser.getStationResults(new Station("80046"));
    for (Line l : lines.getLines()) {
      System.out.println(
          "Line "
              + l.getLine()
              + " departs: "
              + l.getDepTime().get(Calendar.HOUR_OF_DAY)
              + ":"
              + l.getDepTime().get(Calendar.MINUTE)
              + " and is "
              + l.getDepTimeDeviation()
              + " minutes late");
    }
  }
    @Override
    public void run() {
      String from = txtFrom.getText();
      String to = txtToStation.getText();
      String searchURL = Constants.getURL(from, to, 10);
      Journeys journeys = Parser.getJourneys(searchURL);

      txtToResult.setText("");

      for (Journey journey : journeys.getJourneys()) {
        String time =
            journey.getDepDateTime().get(Calendar.HOUR_OF_DAY)
                + ":"
                + journey.getDepDateTime().get(Calendar.MINUTE);
        txtToResult.append(
            " Departs "
                + time
                + " that is in "
                + journey.getTimeToDeparture()
                + " minutes. And it is "
                + journey.getDepTimeDeviation()
                + " min late"
                + "\n");
      }
    }
 @Override
 public void run() {
   String info = txtSearch.getText();
   String from = txtFrom.getText();
   String to = txtToStation.getText();
   String searchURL = Constants.getURL(from, to, 20);
   ArrayList<Station> searchStations = new ArrayList<Station>();
   searchStations.addAll(Parser.getStationsFromURL(stationName));
   txtareaResult.setText("");
   for (Station s : searchStations) {
     /** System.out.println(s.getStationName() +" number:" +s.getStationNbr()); */
     txtareaResult.append(
         s.getStationNbr()
             + " "
             + s.getStationName()
             + " "
             + s.getLatitude()
             + " "
             + s.getLongitude()
             + "\n");
   }
 }