Beispiel #1
0
 /**
  * Returns all possible itineraries sorted by total cost, form origin to destination leaving on
  * date, with 6 hours or less of transferring from one flight to another.
  *
  * @param date the date of departure
  * @param origin the place of departure
  * @param destination the place of arrival
  * @return String of all possible itineraries sorted by total cost, form origin to destination
  *     leaving on date, with >=6 hours of transfer time
  */
 public static String getItinerariesSortedByCost(String date, String origin, String destination) {
   String res = "";
   ArrayList<Itinerary> itineraries = Client.getItinerariesSortedByCost(date, origin, destination);
   for (Itinerary itinerary : itineraries) {
     res += itinerary.toString() + "\n";
   }
   res = res.trim();
   return res;
 }
  private static void getNewBooking() {
    Itinerary i = null;

    while (i == null) {
      System.out.print("Departure city: ");
      String depCity = input.next();

      System.out.print("Destination city: ");
      String destCity = input.next();

      i = service.getItinerary(depCity, destCity);

      if (i != null) {
        System.out.println("A possible itinerary is:");
        for (Flight flight : i.flights) {
          System.out.println(
              "    Dep: " + flight.getDepartureCity() + "    Dest: " + flight.getDestinationCity());
        }
      } else {
        System.out.println("No routes for these cities. Please try another.");
      }
    }

    String price = "";
    String date = null;

    while (price.equals("")) {
      System.out.print("Select a date (aaaa-mm-dd): ");
      date = input.next();

      price = service.checkAvailable(i.getId(), date);

      if (price.equals("")) {
        System.out.println("No flights available in that date. Please try another.");
      } else {
        System.out.println("The price for this flight is " + price);
      }
    }

    System.out.print(
        "If you want to proceed with the booking, please insert the credit card. "
            + "Otherwise insert 0: ");
    String creditCard = input.next();

    if (!creditCard.equals("0")) {
      BookedFlight booking = new BookedFlight();
      booking.setDate(date);
      booking.setItineraryId(i.getId());

      booking = service.postBooking(booking, creditCard);

      System.out.println("Your booking id is " + booking.getBookingId() + ".");
      System.out.println("Your flight was booked with success!");
    }
  }
Beispiel #3
0
 private boolean calculateMisdirectionStatus(Itinerary itinerary) {
   if (lastEvent == null) {
     return false;
   } else {
     return !itinerary.isExpected(lastEvent);
   }
 }
Beispiel #4
0
 private Date calculateEta(Itinerary itinerary) {
   if (onTrack()) {
     return itinerary.getFinalArrivalDate();
   } else {
     return ETA_UNKOWN;
   }
 }
Beispiel #5
0
  private HandlingActivity calculateNextExpectedActivity(
      RouteSpecification routeSpecification, Itinerary itinerary) {
    if (!onTrack()) return NO_ACTIVITY;

    if (lastEvent == null)
      return new HandlingActivity(HandlingEvent.Type.RECEIVE, routeSpecification.getOrigin());

    switch (lastEvent.getType()) {
      case LOAD:
        for (Leg leg : itinerary.getLegs()) {
          if (leg.getLoadLocation().equals(lastEvent.getLocation())) {
            return new HandlingActivity(
                HandlingEvent.Type.UNLOAD, leg.getUnloadLocation(), leg.getVoyage());
          }
        }

        return NO_ACTIVITY;

      case UNLOAD:
        for (Iterator<Leg> it = itinerary.getLegs().iterator(); it.hasNext(); ) {
          final Leg leg = it.next();
          if (leg.getUnloadLocation().equals(lastEvent.getLocation())) {
            if (it.hasNext()) {
              final Leg nextLeg = it.next();
              return new HandlingActivity(
                  HandlingEvent.Type.LOAD, nextLeg.getLoadLocation(), nextLeg.getVoyage());
            } else {
              return new HandlingActivity(HandlingEvent.Type.CLAIM, leg.getUnloadLocation());
            }
          }
        }

        return NO_ACTIVITY;

      case RECEIVE:
        final Leg firstLeg = itinerary.getLegs().iterator().next();
        return new HandlingActivity(
            HandlingEvent.Type.LOAD, firstLeg.getLoadLocation(), firstLeg.getVoyage());

      case CLAIM:
      default:
        return NO_ACTIVITY;
    }
  }
Beispiel #6
0
 @Override
 public void coGroup(
     Iterable<Itinerary> itineraries, Iterable<MIDT> midts, Collector<Itinerary> out)
     throws Exception {
   Iterator<Itinerary> itinIter = itineraries.iterator();
   Iterator<MIDT> midtIter = midts.iterator();
   if (!midtIter.hasNext()) {
     out.collect(itinIter.next());
   } else if (!itinIter.hasNext()) {
     out.collect(TAUtil.MIDTToItinerary(midtIter.next()));
   } else {
     MIDT midt = midtIter.next();
     Itinerary itin = itinIter.next();
     itin.f13 = midt.f11;
     out.collect(itin);
   }
   if (itinIter.hasNext()) {
     throw new Exception("More than one Itinerary: " + itinIter.next().toString());
   }
   if (midtIter.hasNext()) {
     throw new Exception("More than one MIDT: " + midtIter.next().toString());
   }
 }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {

    if (inflater == null)
      inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) convertView = inflater.inflate(R.layout.itinerary_row, null);

    TextView date = (TextView) convertView.findViewById(R.id.textView_row_date);
    TextView client = (TextView) convertView.findViewById(R.id.textView_row_client);
    TextView vendor = (TextView) convertView.findViewById(R.id.textView_row_vendor);
    TextView material = (TextView) convertView.findViewById(R.id.textView_row_material);
    ImageView status = (ImageView) convertView.findViewById(R.id.imageView_visitStatus);

    // getting Itinerary data for the row
    Itinerary m = itineraryItems.get(position);

    // date
    date.setText(m.getDate());

    // client
    client.setText(m.getClient());

    // vendor
    vendor.setText(m.getVendor());

    // material
    material.setText(m.getMaterial());
    // status
    if (m.isStatus() == 0) {
      status.setImageResource(R.drawable.pendingstatus512x512);
    }
    // TODO replace images with variable size images
    else status.setImageResource(R.drawable.visitok512x512);

    return convertView;
  }