示例#1
0
 /**
  * Used to compare object to eachother for sorting
  *
  * @param o a flight object used to compare the airport source then date
  * @return integer value signaling the difference
  */
 @Override
 public int compareTo(Flight o) {
   if (this.getSource().compareTo(o.getSource()) != 0) {
     return this.getSource().compareTo(o.getSource());
   } else {
     return this.departureTime.toString().compareTo(o.departureTime.toString());
     // return this.getDepartureString().compareTo(o.getDepartureString());
   }
 }
示例#2
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);
  }