25package umontreal.ssj.simevents;
53public abstract class Event implements Comparable<Event> {
58 protected double priority;
62 protected double eventTime;
77 public final int getRa() {
81 public final void setRa(
int r) {
139 throw new NullPointerException();
155 public void schedule(
double delay) {
157 throw new IllegalArgumentException(
"Cannot schedule in the past.");
158 if (eventTime > -1.0)
159 throw new IllegalStateException(
"Event already scheduled");
160 eventTime = sim.time() + delay;
161 sim.eventList.add(
this);
169 if (eventTime > -1.0)
170 throw new IllegalStateException(
"Event already scheduled");
171 eventTime = sim.time();
173 sim.eventList.addFirst(
this);
191 if (eventTime > -1.0)
192 throw new IllegalStateException(
"Event already scheduled");
193 eventTime = other.eventTime;
194 priority = other.priority;
195 sim.eventList.addBefore(
this, other);
205 if (eventTime > -1.0)
206 throw new IllegalStateException(
"Event already scheduled");
207 eventTime = other.eventTime;
208 priority = other.priority;
209 sim.eventList.addAfter(
this, other);
219 throw new IllegalArgumentException(
"Cannot schedule in the past.");
220 if (eventTime < -1.0)
221 throw new IllegalStateException(
"Event not scheduled");
222 sim.getEventList().remove(
this);
223 eventTime = sim.time() + delay;
224 sim.getEventList().add(
this);
234 boolean removed =
false;
235 if (eventTime >= sim.time())
236 removed = sim.getEventList().remove(
this);
248 public final boolean cancel(String type) {
249 Event ev = sim.getEventList().getFirstOfClass(type);
270 throw new NullPointerException();
271 if (eventTime > -1.0)
272 throw new UnsupportedOperationException(
"Unable to set Simulator, current Event already scheduled");
281 public final double time() {
293 if (eventTime > -1.0)
294 throw new UnsupportedOperationException(
"Unable to set time, current Event already scheduled");
315 if (eventTime > -1.0)
316 throw new UnsupportedOperationException(
"Unable to set priority, current Event already scheduled");
317 this.priority = priority;
328 if (eventTime < e.
time())
330 if (eventTime > e.
time())
334 if (priority < e.priority())
336 if (priority > e.priority())
346 public abstract void actions();
boolean cancel()
Cancels this event before it occurs.
void scheduleNext()
Schedules this event as the first event in the event list, to be executed at the current time (as the...
void scheduleAfter(Event other)
Schedules this event to happen just after, and at the same time, as the event other.
void reschedule(double delay)
Cancels this event and reschedules it to happen in delay time units.
final void setPriority(double priority)
Sets the priority of this event to inPriority.
Event()
Constructs a new event instance, which can be placed afterwards into the event list of the default si...
final void setSimulator(Simulator sim)
Sets the simulator associated with this event to sim.
abstract void actions()
This is the method that is executed when this event occurs.
int compareTo(Event e)
Compares this object with the specified object e for order.
void schedule(double delay)
Schedules this event to happen in delay time units, i.e., at time sim.time() + delay,...
final Simulator simulator()
Returns the simulator linked to this event.
void scheduleBefore(Event other)
Schedules this event to happen just before, and at the same time, as the event other.
final double time()
Returns the (planned) time of occurence of this event.
final double priority()
Returns the priority of this event.
final void setTime(double time)
Sets the (planned) time of occurence of this event to time.
Represents the executive of a discrete-event simulator.
static Simulator getDefaultSimulator()
Returns the default simulator instance used by the deprecated class.