首页 > 代码库 > CloudSim源代码之FutureQueue

CloudSim源代码之FutureQueue

技术分享
package org.cloudbus.cloudsim.core;import java.util.Collection;import java.util.Iterator;import java.util.SortedSet;import java.util.TreeSet;/**执行未来事件队列 * This class implements the future event queue. * The event queue uses a TreeSet in order to store the events. */ public class FutureQueue {    /** The sorted set.分类集合 */    private final SortedSet<SimEvent> sortedSet = new TreeSet<SimEvent>();    private long serial = 0;    /**队列增加新的事件     * Add a new event to the queue. Adding a new event to the queue     * preserves the temporal order of the events in the queue.     *     * @param newEvent The event to be put in the queue.     */    public void addEvent(SimEvent newEvent) {        newEvent.setSerial(serial++);        sortedSet.add(newEvent);    }    /**队列返回一迭代程序     * Returns an iterator to the queue.     *     * @return the iterator     */    public Iterator<SimEvent> iterator() {        return sortedSet.iterator();    }    /**返回事件队列大小     * Returns the size of this event queue.     *     * @return the size     */    public int size() {        return sortedSet.size();    }    /**从队列中移除事件     * Removes the event from the queue.     *     * @param event the event     *     * @return true, if successful     */    public boolean remove(SimEvent event) {        return sortedSet.remove(event);    }    /**从队列中移除所有事件     * Removes all the events from the queue.     *     * @param events the events     *     * @return true, if successful     */    public boolean removeAll(Collection<SimEvent> events) {        return sortedSet.removeAll(events);    }    /**清除队列     * Clears the queue.     */    public void clear(){        sortedSet.clear();    }}
View Code

 

CloudSim源代码之FutureQueue