umontreal.iro.lecuyer.simevents.eventlist
Class DoublyLinked
- java.lang.Object
-
- umontreal.iro.lecuyer.simevents.eventlist.DoublyLinked
-
public class DoublyLinked extends java.lang.Object implements EventList
An implementation ofEventListusing a doubly linked linear list. Each event is stored into a list node that contains a pointer to its following and preceding events. Adding an event requires a linear search to keep the event list sorted by event time and priority. Removing the first event is done in constant time because it simply removes the first list node. List nodes are recycled for increased memory management efficiency.
-
-
Constructor Summary
Constructors Constructor and Description DoublyLinked()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidadd(Event ev)Adds a new event in the event list, according to the time of ev.voidaddAfter(Event ev, Event other)Same asadd, but adds the new event ev immediately after the event other in the list.voidaddBefore(Event ev, Event other)Same asadd, but adds the new event ev immediately before the event other in the list.voidaddFirst(Event ev)Adds a new event at the beginning of the event list.voidclear()Empties the event list, i.e., cancels all events.EventgetFirst()Returns the first event in the event list.<E extends Event>
EgetFirstOfClass(java.lang.Class<E> cl)Returns the first event of the class E (a subclass of Event) in the event list.EventgetFirstOfClass(java.lang.String cl)Returns the first event of the class cl (a subclass of Event) in the event list.booleanisEmpty()Returns true if and only if the event list is empty (no event is scheduled).java.util.Iterator<Event>iterator()java.util.ListIterator<Event>listIterator()Returns a list iterator over the elements of the class Event in this list.booleanremove(Event ev)Removes the event ev from the event list (cancels this event).EventremoveFirst()Removes the first event from the event list (to cancel or execute this event).java.lang.StringtoString()
-
-
-
Method Detail
-
isEmpty
public boolean isEmpty()
Description copied from interface:EventListReturns true if and only if the event list is empty (no event is scheduled).
-
clear
public void clear()
Description copied from interface:EventListEmpties the event list, i.e., cancels all events.
-
add
public void add(Event ev)
Description copied from interface:EventListAdds a new event in the event list, according to the time of ev. If the event list contains events scheduled to happen at the same time as ev, ev must be added after all these events.
-
addFirst
public void addFirst(Event ev)
Description copied from interface:EventListAdds a new event at the beginning of the event list. The given event ev will occur at the current simulation time.
-
addBefore
public void addBefore(Event ev, Event other)
Description copied from interface:EventListSame asadd, but adds the new event ev immediately before the event other in the list.
-
addAfter
public void addAfter(Event ev, Event other)
Description copied from interface:EventListSame asadd, but adds the new event ev immediately after the event other in the list.
-
getFirst
public Event getFirst()
Description copied from interface:EventListReturns the first event in the event list. If the event list is empty, returns null.
-
getFirstOfClass
public Event getFirstOfClass(java.lang.String cl)
Description copied from interface:EventListReturns the first event of the class cl (a subclass of Event) in the event list. If no such event is found, returns null.- Specified by:
getFirstOfClassin interfaceEventList- Returns:
- the first event of class cl, or null if no such event exists in the list
-
getFirstOfClass
public <E extends Event> E getFirstOfClass(java.lang.Class<E> cl)
Description copied from interface:EventListReturns the first event of the class E (a subclass of Event) in the event list. If no such event is found, returns null.- Specified by:
getFirstOfClassin interfaceEventList- Returns:
- the first event of class cl, or null if no such event exists in the list
-
remove
public boolean remove(Event ev)
Description copied from interface:EventListRemoves the event ev from the event list (cancels this event). Returns true if and only if the event removal has succeeded.
-
removeFirst
public Event removeFirst()
Description copied from interface:EventListRemoves the first event from the event list (to cancel or execute this event). Returns the removed event. If the list is empty, then null is returned.- Specified by:
removeFirstin interfaceEventList- Returns:
- the first event removed from the list, or null if the list is empty
-
iterator
public java.util.Iterator<Event> iterator()
- Specified by:
iteratorin interfacejava.lang.Iterable<Event>
-
listIterator
public java.util.ListIterator<Event> listIterator()
Description copied from interface:EventListReturns a list iterator over the elements of the class Event in this list.- Specified by:
listIteratorin interfaceEventList- Returns:
- a list iterator over the elements of the class Event in this list
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-
DMelt 3.0 © DataMelt by jWork.ORG