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; } } }
public void commandLETTER( String srcPostOffice, String pickUpPerson, String dstPostOffice, String returnPerson, int systemTime) { int srcOfficeIndex = getOfficeIndex(srcPostOffice); if (srcOfficeIndex != -1) { newLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice, dstPostOffice); int dstOfficeIndex = getOfficeIndex(dstPostOffice); if (dstOfficeIndex != -1) { if (isNewCriminal(newCriminals, pickUpPerson) == false && isOldCriminal("wanted.txt", pickUpPerson) == false) { if (((Office) offices.get(srcOfficeIndex)).currentItems.size() < ((Office) offices.get(srcOfficeIndex)).maxCap) { Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); if (returnPerson.equals("NONE")) { newItem.returnRecipent = ""; } else { newItem.returnRecipent = new String(returnPerson); } newItem.dayGotInSystem = systemTime; newItem.type = new String("letter"); newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedLetterEntry("log_" + srcPostOffice + ".txt", dstPostOffice); } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } }
public void commandPACKAGE( String srcPostOffice, String pickUpPerson, String dstPostOffice, int funds, int packageLen) { int srcOfficeIndex = getOfficeIndex(srcPostOffice); if (srcOfficeIndex != -1) { newPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice, dstPostOffice); int dstOfficeIndex = getOfficeIndex(dstPostOffice); if (dstOfficeIndex != -1) { if (isNewCriminal(newCriminals, pickUpPerson) == false && isOldCriminal("wanted.txt", pickUpPerson) == false) { if (((Office) offices.get(srcOfficeIndex)).currentItems.size() < ((Office) offices.get(srcOfficeIndex)).maxCap) { if (funds >= ((Office) offices.get(srcOfficeIndex)).postagePrice) { if (packageLen <= ((Office) offices.get(srcOfficeIndex)).maxPackageSize) { if (packageLen <= ((Office) offices.get(dstOfficeIndex)).maxPackageSize) { // Clean insertion Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); newItem.funds = funds; newItem.length = packageLen; newItem.type = new String("package"); newItem.dayGotInSystem = currentDay; newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedPackageEntry("log_" + srcPostOffice + ".txt", dstPostOffice); } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else if (funds >= (((Office) offices.get(srcOfficeIndex)).postagePrice + ((Office) offices.get(srcOfficeIndex)).persuationPrice)) { // Illegal insertion Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); newItem.funds = funds; newItem.length = packageLen; newItem.type = new String("package"); newItem.dayGotInSystem = currentDay; newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedPackageEntry("log_" + srcPostOffice + ".txt", dstPostOffice); briberyDetectedEntry("log_master.txt", srcPostOffice); } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } }