예제 #1
0
  /**
   * Write all the matching fights
   *
   * @param response gives to the client
   * @param name the name of the airline
   * @param src source of the airport
   * @param dest destination of the airport
   * @throws IOException
   */
  private void writeAllMatchedMappings(
      HttpServletResponse response, String name, String src, String dest) throws IOException {
    int matches = 0;
    PrintWriter pw = response.getWriter();
    pw.println(Messages.getMappingCount(data.size()));

    for (Map.Entry<String, Airline> entry : this.data.entrySet()) {
      if (entry.getKey().equals(name)) {
        pw.println(entry.getKey());
        for (Object flight : entry.getValue().getFlights()) {
          Flight flight1 = (Flight) flight;
          if (flight1.getSource().equals(src.toUpperCase())
              && flight1.getDestination().equals(dest.toUpperCase())) {
            pw.println("\t" + flight.toString() + " Duration(minutes) " + flight1.getDuration());
            ++matches;
          }
        }
      }
    }
    if (matches == 0) {
      pw.println("There are direct flights between the specified airports");
    }

    pw.flush();

    response.setStatus(HttpServletResponse.SC_OK);
  }
예제 #2
0
  /**
   * Method used to write the base url
   *
   * @param response gives to the client
   * @throws IOException
   */
  private void writeAllMappings(HttpServletResponse response) throws IOException {
    PrintWriter pw = response.getWriter();
    pw.println(Messages.getMappingCount(data.size()));

    for (Map.Entry<String, Airline> entry : this.data.entrySet()) {
      pw.println(entry.getKey());
      for (Object flight : entry.getValue().getFlights()) {
        Flight flight1 = (Flight) flight;
        pw.println("\t" + flight.toString() + " Duration(minutes) " + flight1.getDuration());
      }
    }

    pw.flush();

    response.setStatus(HttpServletResponse.SC_OK);
  }
예제 #3
0
  /**
   * Finds all the matched airlines and flights
   *
   * @param response gives to the client
   * @param name the name of the airline
   * @throws IOException
   */
  private void writeAllMatchedAirlineMappings(HttpServletResponse response, String name)
      throws IOException {
    int matches = 0;
    PrintWriter pw = response.getWriter();
    pw.println(Messages.getMappingCount(data.size()));

    for (Map.Entry<String, Airline> entry : this.data.entrySet()) {
      if (entry.getKey().equals(name)) {
        pw.println(entry.getKey());
        for (Object flight : entry.getValue().getFlights()) {
          Flight flight1 = (Flight) flight;
          ++matches;
          pw.println("\t" + flight.toString() + " Duration(minutes) " + flight1.getDuration());
        }
      }
    }

    if (matches == 0) {
      pw.println("No airline matches exist for that search");
    }
    pw.flush();

    response.setStatus(HttpServletResponse.SC_OK);
  }