예제 #1
0
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();
    long waitTime = 0l;
    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      for (int x = 0; x < fdistan.getFoodies().size(); x++) {
        Foodie f = fdistan.getFoodies().get(x);
        if (f.getfStatus() == foodieStatus.WAITING) {

          if ((fdistan.getMg().hasInventory(Foodistan.getfoodistan().getInv(), 1) == false)
              || (fdistan.getMg().calculateDiscount() < f.getFoodieDiscount())) {
          } else {
            waitTime = System.currentTimeMillis() - f.getWaitStartTime();
            if (waitTime > fdistan.getMaxWaitingTime()) fdistan.setMaxWaitingTime(waitTime);
            fdistan.setAvgWaitingTime(fdistan.getAvgWaitingTime() + waitTime);
            Item itm = fdistan.getMg().getItem(fdistan.getInv());
            fdistan.getFoodies().get(x).consumeItem(itm);
            fdistan.setAvgItemLifeTime(
                fdistan.getAvgItemLifeTime()
                    + (System.currentTimeMillis() - itm.getItemStartTime()));
            fdistan.getOdrsOnHold().remove(0).setOrdrStatus(orderStatus.COMPLETE);
            fdistan.getFoodiesOnHold().remove(0);
            fdistan.setBurgerNeeded(fdistan.getBurgerNeeded() - 1);
            fdistan.setOrdersDelivered(Foodistan.getfoodistan().getOrdersDelivered() + 1);
          }
        }
      }
    }
  }
예제 #2
0
  public void run() {
    Foodistan fdistan = Foodistan.getfoodistan();

    while (System.currentTimeMillis() <= Foodistan.getfoodistan().getFoodistanEndTime()) {
      // System.out.println(fdistan.getInv().items.isEmpty());

      long waitTime = 180000L;
      if (!fdistan.getInv().items.isEmpty()) {

        if (System.currentTimeMillis()
            > (180000L + fdistan.getInv().items.peek().getItemStartTime())) {
          fdistan.getInv().items.poll();
          fdistan.setBurgersWasted(fdistan.getBurgersWasted() + 1);
          fdistan.setAvgItemLifeTime(fdistan.getAvgItemLifeTime() + ItemType.BURGER.getLifeTime());
        }
        waitTime =
            (fdistan.getInv().items.peek().getItemStartTime() + 180000L)
                - System.currentTimeMillis();
      }
      System.out.println("Stale burgers it ");
      if (waitTime < 0) continue;
      try {

        Thread.currentThread().sleep(waitTime);
      } catch (Exception e) {
        e.printStackTrace();
      }

      /*
      while(!(fdistan.getInv().items.isEmpty())){
          System.out.println(fdistan.getInv().items.isEmpty());
      	System.out.println("System time update " + System.currentTimeMillis());
      	System.out.println("System time update " + fdistan.getInv().items.peek().getItemStartTime());
      	System.out.println("System time update " + (System.currentTimeMillis() - fdistan.getInv().items.peek().getItemStartTime()));

      	//System.out.println("Outside it ");
      	if (System.currentTimeMillis() > (180000L + fdistan.getInv().items.peek().getItemStartTime())){
      		fdistan.getInv().items.poll();
      		System.out.println("inside it ");
      		//jjSystem.exit(1);

      		fdistan.setBurgersWasted(fdistan.getBurgersWasted()+1);
      		fdistan.setAvgItemLifeTime(fdistan.getAvgItemLifeTime()+ItemType.BURGER.getLifeTime());
      	}else
      		System.out.println("outside it ");
      }  */
    }
  }