Beispiel #1
0
  void getFileContent(File file) throws JAXBException, FileNotFoundException {
    JAXBContext jc = JAXBContext.newInstance("ch.bfh.ti.lottery.tickets");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    File tmpFile = new File("ticPool.xml");

    // UnMashal the XML - File

    Tickets tickets = (Tickets) unmarshaller.unmarshal(file);
    int columnCount = 1;
    for (int i = 0; i < tickets.getTicket().size(); i++) {

      /*
       * every loop is a ticket
       */

      if (tickets.getTicket().get(i) instanceof Ticket) {
        Ticket ticket = (Ticket) tickets.getTicket().get(i);
        int ticketId = ticket.getTicketId();

        String time =
            ticket.getTimeStamp().getDay()
                + "."
                + ticket.getTimeStamp().getMonth()
                + "."
                + ticket.getTimeStamp().getYear();
        if (ticket.getValidity() == 1 && lotto.getDate().equals(time)) { // &&
          SuperStars superStar = ticket.getSuperStars();

          for (int j = 0; j < ticket.getPlays().getPlay().size(); j++) {

            Play play = (Play) ticket.getPlays().getPlay().get(j);
            Numbers numbers = play.getNumbers();
            Stars stars = play.getStars();

            int hasSuperStar = 0;
            int playId = play.getPlayId();
            int tmp = 0;
            int starTmp = 0;

            for (int number : numbers.getNumber()) {
              // System.out.println(number + "-" +
              // lotto.getNumbers());
              if (lotto.getNumbers().contains(number)) {
                tmp++;
                // System.out.println("HIT" + tmp);
              }
            }
            // System.out.println(" Spiel ENDE");

            for (int starNumber : stars.getStar()) {
              if (lotto.getStarNumbers().contains(starNumber)) {
                starTmp++;
              }
            }

            for (SuperStar ele : superStar.getSuperStar()) {
              if (ele.isSelected()) {
                if (lotto.getSuperStar().equals(ele.getValue())) {
                  hasSuperStar = 1;
                }
              }
            }

            grid_ListResults.addColumn(columnCount, new Pane());
            grid_ListResults.add(new Label(ticketId + "-" + playId), 0, columnCount);
            grid_ListResults.add(new Label(tmp + ""), 1, columnCount);
            grid_ListResults.add(new Label(starTmp + ""), 2, columnCount);
            grid_ListResults.add(new Label(hasSuperStar + ""), 3, columnCount);
            columnCount++;
          }
        }
      }
    }
    System.out.println("Fertig");
  }