package org.cloudbus.cloudsim.core; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; /**【此类执行延期的事件队列】 * This class implements the deferred event queue used by Simulation. * The event queue uses a linked list to store the events. */ public class DeferredQueue { /** The list. 列表*/ private final List<SimEvent> list = new LinkedList<SimEvent>(); /** The max time. 最大时间 */ private double maxTime = -1; /**【给队列增加新的事件】 * Adds a new event to the queue. * preserves the temporal order of the events. * * @param newEvent The event to be added to the queue. */ public void addEvent(SimEvent newEvent) { // The event has to be inserted as the last of all events // with the same event_time(). Yes, this matters.加入新事件 double eventTime = newEvent.eventTime(); if (eventTime >= maxTime) { list.add(newEvent); maxTime = eventTime; return; } ListIterator<SimEvent> iterator = list.listIterator(); SimEvent event; while (iterator.hasNext()) { event = iterator.next(); if (event.eventTime() > eventTime) { iterator.previous(); iterator.add(newEvent); return; } } list.add(newEvent); } /**返回队列中事件迭代器 * Returns an iterator to the events in the queue. * * @return the iterator */ public Iterator<SimEvent> iterator() { return list.iterator(); } /**返回事件队列大小 * Returns the size of this event queue. * * @return the number of events in the queue. */ public int size() { return list.size(); } /**清除队列 * Clears the queue. */ public void clear(){ list.clear(); } }
时间: 2024-11-06 18:09:08