/** * Checks if counters are empty * * @return boolean */ public boolean countersEmpty() { Iterator<CheckoutCounter> iter = checkoutCounters.iterator(); while (iter.hasNext()) { CheckoutCounter counter = iter.next(); if (!counter.isEmpty()) return false; } return true; }
/** * Simulates supermarket time one minute * * @return void */ public void simMinute() { if (!isClosed) { Distribution<Integer> custFlowDistrib = this.timeDistrib.get(minutesElapsed); if (custFlowDistrib != null) { int numCust = custFlowDistrib.get(Math.random()); for (int i = 0; i < numCust; i++) { int processTime = this.custProcTimeDistrib.get(Math.random()); Customer cust = new Customer(processTime); CheckoutCounter bestCounter = null; Iterator<CheckoutCounter> iter = checkoutCounters.iterator(); while (iter.hasNext()) { CheckoutCounter counter = iter.next(); if (bestCounter == null || bestCounter.customersInLine() > counter.customersInLine()) { bestCounter = counter; } } bestCounter.addCustomer(cust); } } else { isClosed = true; } } if (!isComplete()) { Iterator<CheckoutCounter> iter = checkoutCounters.iterator(); while (iter.hasNext()) { CheckoutCounter counter = iter.next(); counter.increaseWaitingTime(); counter.processCustomer(); } } minutesElapsed++; }