| 1 | package desmoj.core.simulator; |
| 2 | |
| 3 | /** |
| 4 | * This interface describes the set of methods an event-list carrying the |
| 5 | * scheduled events and entities in a temporal order has to implement. This is a |
| 6 | * part of the framework that does not have to be implemented by the user in |
| 7 | * order to get a simulation running, since the scheduler already uses the class |
| 8 | * EventVector as default EventList construction. Since each step in the |
| 9 | * discrete simulation requires searching and manipulating the event-list, this |
| 10 | * is probably one of the best places in the framework to optimize execution |
| 11 | * performance. Especially if special models show specific behaviour i.e. |
| 12 | * primarily inserting new events at the very end of the event-list, other |
| 13 | * implementations of the event-list might support faster access times. |
| 14 | * |
| 15 | * @see EventVectorList |
| 16 | * |
| 17 | * @version DESMO-J, Ver. 2.3.3 copyright (c) 2011 |
| 18 | * @author Tim Lechler |
| 19 | * |
| 20 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 21 | * you may not use this file except in compliance with the License. You |
| 22 | * may obtain a copy of the License at |
| 23 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | * |
| 25 | * Unless required by applicable law or agreed to in writing, software |
| 26 | * distributed under the License is distributed on an "AS IS" |
| 27 | * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express |
| 28 | * or implied. See the License for the specific language governing |
| 29 | * permissions and limitations under the License. |
| 30 | * |
| 31 | */ |
| 32 | public abstract class EventList { |
| 33 | /** |
| 34 | * Implement this method to let the user obtain a new event-note. This |
| 35 | * resembles the design pattern of a factory method [Gamm95, p. 107]. The |
| 36 | * use of a factory method here ensures that always the correct |
| 37 | * implementation of an event-note is used together with the current active |
| 38 | * implementation of an event-list, since both might be tightly coupled. |
| 39 | * (Note that this is not mandatory as proven in the default implementation) |
| 40 | * |
| 41 | * @return EventNote : The new event-note that contains all the information |
| 42 | * handed as parameters |
| 43 | * @param who |
| 44 | * Entity : The entity that is to be changed by the event to |
| 45 | * happen |
| 46 | * @param what |
| 47 | * Event : The type of Event that is going to happen |
| 48 | * @param when |
| 49 | * TimeInstant : The point of time at which the event is going to |
| 50 | * happen to the entity |
| 51 | */ |
| 52 | abstract EventNote createEventNote(Entity who, Event<Entity> what, TimeInstant when); |
| 53 | |
| 54 | /** |
| 55 | * Returns the first event-note in the event-list. That EventNote contains |
| 56 | * information about the next event to happen and will be the next event |
| 57 | * processed by the scheduler. |
| 58 | * |
| 59 | * @return EventNote : The first event-note in the event-list |
| 60 | */ |
| 61 | abstract EventNote firstNote(); |
| 62 | |
| 63 | /** |
| 64 | * Inserts a new event-note into the event-list. Event notes are sorted by the |
| 65 | * point if time they are scheduled to happen. This method ensures that the |
| 66 | * new event-note is inserted in the right place in the event-list, scanning |
| 67 | * through the list whenever a new event-note has to be inserted. |
| 68 | * |
| 69 | * @param newNote |
| 70 | * EventNote : The event-note to be sorted into the event-list |
| 71 | */ |
| 72 | abstract void insert(EventNote newNote); |
| 73 | |
| 74 | /** |
| 75 | * Inserts the new event-note straight after the other specified EventNote. |
| 76 | * This other EventNote must already be scheduled. Otherwise a warning will |
| 77 | * be issued and the method returns without changing the event-list. |
| 78 | * |
| 79 | * @param afterNote |
| 80 | * EventNote : The event-note already scheduled, that the new |
| 81 | * EventNote is supposed to be inserted after. |
| 82 | * @param newNote |
| 83 | * EventNote : The new event-note to be inserted before the |
| 84 | * specified EventNote |
| 85 | */ |
| 86 | abstract void insertAfter(EventNote afterNote, EventNote newNote); |
| 87 | |
| 88 | /** |
| 89 | * Inserts the given EventNote at the first position in the event-list. The |
| 90 | * Event encapsulated in that EventNote will probably be the next event to |
| 91 | * be processed by the scheduler (unless some other calls to this method are |
| 92 | * made before). Note that this operation changes the scheduled time of the |
| 93 | * given EventNote to the actual simulation time to keep the temporal order |
| 94 | * of the event-list. |
| 95 | * |
| 96 | * @param newNote |
| 97 | * EventNote : The event-note to be inserted at the first position |
| 98 | * in the event-list |
| 99 | */ |
| 100 | abstract void insertAsFirst(EventNote newNote); |
| 101 | |
| 102 | /** |
| 103 | * Inserts an event-note at the last position in the event-list. Note that |
| 104 | * the simulation time of the given EventNote will be set to be the same as |
| 105 | * the last EventNote in the event-list to keep the temporal order of the |
| 106 | * evnet-list. |
| 107 | * |
| 108 | * @param newNote |
| 109 | * EventNote : The event-note to be inserted at the last position |
| 110 | * in the event-list |
| 111 | */ |
| 112 | abstract void insertAsLast(EventNote newNote); |
| 113 | |
| 114 | /** |
| 115 | * Inserts the new event-note straight before the other specified EventNote. |
| 116 | * This other EventNote must already be scheduled. Otherwise the position to |
| 117 | * insert the given EventNote can not be determined, resulting in a |
| 118 | * ItemNotScheduledException being thrown. |
| 119 | * |
| 120 | * @param beforeNote |
| 121 | * EventNote : The event-note already scheduled, that the new |
| 122 | * EventNote is supposed to be inserted before. |
| 123 | * @param newNote |
| 124 | * EventNote : The new event-note to be inserted before the |
| 125 | * specified EventNote |
| 126 | */ |
| 127 | abstract void insertBefore(EventNote beforeNote, EventNote newNote); |
| 128 | |
| 129 | /** |
| 130 | * Tests if there are any scheduled events contained in the event-list. If |
| 131 | * the event-list happens to be empty during the run of a simulation, this |
| 132 | * is a criterium to stop the simulation, since no further action is |
| 133 | * scheduled. |
| 134 | * |
| 135 | * @return boolean : Is <code>true</code> if there are no EventNote |
| 136 | * contained in the event-list, <code>false</code> otherwise. |
| 137 | */ |
| 138 | abstract boolean isEmpty(); |
| 139 | |
| 140 | /** |
| 141 | * Returns the last EventNote in the event-list. |
| 142 | * |
| 143 | * @return EventNote : The last EventNote in the event-list |
| 144 | */ |
| 145 | abstract EventNote lastNote(); |
| 146 | |
| 147 | /** |
| 148 | * Returns the next event-note in the event-list relative to the given |
| 149 | * EventNote. If the given EventNote is not contained in the event-list or |
| 150 | * happens to be the last EventNote in the event-list, <code>null</code> |
| 151 | * will be returned. |
| 152 | * |
| 153 | * @return EventNote : The event-note following the given EventNote or |
| 154 | * <ocde>null</code> if the given EventNote was last or not found |
| 155 | * @param origin |
| 156 | * EventNote : The event-note whose successor is wanted |
| 157 | */ |
| 158 | abstract EventNote nextNote(EventNote origin); |
| 159 | |
| 160 | /** |
| 161 | * Returns the previous EventNote in the event-list relative to the given |
| 162 | * EventNote. If the given EventNote is not contained in the event-list or |
| 163 | * happens to be the first event-note in the evnet-list, <code>null</code> |
| 164 | * will be returned. |
| 165 | * |
| 166 | * @return EventNote : The event-note following the given EventNote or |
| 167 | * <ocde>null</code> if the given EventNote was first or not found |
| 168 | * @param origin |
| 169 | * EventNote : The event-note whose predecessor is wanted |
| 170 | */ |
| 171 | abstract EventNote prevNote(EventNote origin); |
| 172 | |
| 173 | /** |
| 174 | * Removes the given EventNote from the event-list. |
| 175 | * |
| 176 | * @param note |
| 177 | * EventNote . The event-note to be removed from the event-list |
| 178 | */ |
| 179 | abstract void remove(EventNote note); |
| 180 | |
| 181 | /** |
| 182 | * Removes the first event-note from the event-list. |
| 183 | */ |
| 184 | abstract void removeFirst(); |
| 185 | } |