Exemple #1
0
 public void deliverTransitItems() {
   for (int i = 0; i < inTransit.size(); ) {
     if (((Item) inTransit.get(i)).daysInTransit > ((Item) inTransit.get(i)).delivaryTime) {
       transitArrivedEntry("log_" + ((Item) inTransit.get(i)).toOffice + ".txt");
       int dstOfficeIndex = getOfficeIndex(((Item) inTransit.get(i)).toOffice);
       if (((Office) offices.get(dstOfficeIndex)).currentItems.size()
           < ((Office) offices.get(dstOfficeIndex)).maxCap) {
         if (((Item) inTransit.get(i)).type.equals("letter") == true) {
           Item newItem = new Item();
           newItem.fullCopy((Item) inTransit.get(i));
           newItem.daysInTransit = 0;
           newItem.daysSinceArraival = 0;
           newItem.delivaryTime = ((Office) offices.get(dstOfficeIndex)).transitTime;
           ((Office) offices.get(dstOfficeIndex)).currentItems.add(newItem);
           inTransit.remove(i);
         } else if (((Item) inTransit.get(i)).length
             <= ((Office) offices.get(dstOfficeIndex)).maxPackageSize) {
           Item newItem = new Item();
           newItem.fullCopy((Item) inTransit.get(i));
           newItem.daysInTransit = 0;
           newItem.daysSinceArraival = 0;
           newItem.delivaryTime = ((Office) offices.get(dstOfficeIndex)).transitTime;
           ((Office) offices.get(dstOfficeIndex)).currentItems.add(newItem);
           inTransit.remove(i);
         } else {
           destroyedPackageEntry(
               "log_" + ((Office) offices.get(dstOfficeIndex)).name + ".txt",
               ((Office) offices.get(dstOfficeIndex)).name);
           destroyedPackageEntry("log_master.txt", ((Office) offices.get(dstOfficeIndex)).name);
           inTransit.remove(i);
         }
       } else if (((Item) inTransit.get(i)).type.equals("letter") == true) {
         destroyedLetterEntry(
             "log_" + ((Office) offices.get(dstOfficeIndex)).name + ".txt",
             ((Office) offices.get(dstOfficeIndex)).name);
         destroyedLetterEntry("log_master.txt", ((Office) offices.get(dstOfficeIndex)).name);
         inTransit.remove(i);
       } else {
         destroyedPackageEntry(
             "log_" + ((Office) offices.get(dstOfficeIndex)).name + ".txt",
             ((Office) offices.get(dstOfficeIndex)).name);
         destroyedPackageEntry("log_master.txt", ((Office) offices.get(dstOfficeIndex)).name);
         inTransit.remove(i);
       }
       i = 0;
     } else {
       ++i;
     }
   }
 }
Exemple #2
0
    public void sendItems(Master m) {
      for (int i = 0; i < waitingForSending.size(); ++i) {
        Item newItem = new Item();

        newItem.fullCopy((Item) waitingForSending.get(i));

        m.inTransit.add(newItem);
        transitSentEntry("log_" + name + ".txt");
      }
      waitingForSending.clear();
    }