码迷,mamicode.com
首页 > 其他好文 > 详细

CloudSim源代码之DeferredQueue

时间:2015-01-26 13:25:30      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:

技术分享
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();
    }
}
View Code

 

CloudSim源代码之DeferredQueue

标签:

原文地址:http://www.cnblogs.com/Murcielago/p/4249971.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!