jasi.sim.basic.event
Class AbstractEventBean

java.lang.Object
  extended by jasi.sim.basic.value.AbstractSimValueType
      extended by jasi.sim.basic.value.AbstractComparableObject<Event>
          extended by jasi.sim.basic.event.AbstractEventBean
All Implemented Interfaces:
Event, SimObject, ExtendedComparable<Event>, SimValue, java.io.Serializable, java.lang.Comparable<Event>
Direct Known Subclasses:
AbstractRepeatingEvent, ActivityEvent, LandEvent, SimpleEvent, StartEvent, StopMovementEvent

public abstract class AbstractEventBean
extends AbstractComparableObject<Event>
implements Event

Basic implementation of any simulation event. Events are sorted in first order by their time and in second order by their priority.

See Also:
Serialized Form

Field Summary
 
Fields inherited from interface jasi.sim.basic.event.Event
COMPARATOR, DEFAULT_PRIORITY
 
Constructor Summary
protected AbstractEventBean()
          Construct an event.
protected AbstractEventBean(Time time)
          Construct event for a given time with default priority.
protected AbstractEventBean(Time time, EventListener listener)
          Construct an event for a given time and priority.
protected AbstractEventBean(Time time, int priority)
          Construct an event for a given time and priority.
protected AbstractEventBean(Time time, int priority, EventListener listener)
          Construct an event for a given time and priority.
 
Method Summary
 void addEventListener(EventListener listener)
          Add a model for this event.
protected  Calendar calendar()
          Get the calendar of this event.
 int compareTo(Event e)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one.
 java.util.Collection<EventListener> getEventListeners()
          Get the unmodifiable collection of the event listeners for this event.
 Id getId()
          Retrieve the event's ID.
 int getPriority()
          Retrieve the event's priority.
 Time getTime()
          Retrieve the event's time.
 int hashCode()
          Returns a hash code value for the object.
 void imported(Calendar calendar)
          This event was pushed to a calendar.
 boolean inform()
          Request, if this event is an internal or external event.
 boolean isInitialized()
          Check, if this event has just been created.
 boolean isPopped()
          Check, if this event has already been popped and executed.
 boolean isPushed()
          Check, if this event has already been pushed to a calendar.
 Event popped(Calendar calendar)
          This event was popped from a calendar.
 Event pushed(Calendar calendar)
          This event was pushed to a calendar.
 void removeEventListener(EventListener listener)
          Remove a model for this event.
 void setId(Id id)
          Set the event's ID.
 void setPriority(int priority)
          Initialize the event's priority.
 void setTime(Time time)
          Initialize the event's time.
 java.lang.String toString()
          Returns a string representation of this object.
 
Methods inherited from class jasi.sim.basic.value.AbstractComparableObject
isEQ, isGE, isGT, isLE, isLT, isNE
 
Methods inherited from class jasi.sim.basic.value.AbstractSimValueType
getContent
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jasi.sim.basic.value.ExtendedComparable
isEQ, isGE, isGT, isLE, isLT, isNE
 

Constructor Detail

AbstractEventBean

protected AbstractEventBean()
Construct an event.


AbstractEventBean

protected AbstractEventBean(Time time,
                            int priority)
Construct an event for a given time and priority.

Parameters:
time - The event's time.
priority - The event's priority.

AbstractEventBean

protected AbstractEventBean(Time time)
Construct event for a given time with default priority.

Parameters:
time - The event's time.

AbstractEventBean

protected AbstractEventBean(Time time,
                            int priority,
                            EventListener listener)
Construct an event for a given time and priority.

Parameters:
time - The event's time.
priority - The event's priority.
listener - The event listener (model).

AbstractEventBean

protected AbstractEventBean(Time time,
                            EventListener listener)
Construct an event for a given time and priority.

Parameters:
time - The event's time.
listener - The event listener (model).
Method Detail

imported

public final void imported(Calendar calendar)
This event was pushed to a calendar. This method should only be called by the calendar, where this event has been added to.

Specified by:
imported in interface Event
Parameters:
calendar - The calendar, where this event was pushed to.

pushed

public final Event pushed(Calendar calendar)
This event was pushed to a calendar. This method should only be called by the calendar, where this event has been added to.

Specified by:
pushed in interface Event
Parameters:
calendar - The calendar, where this event was pushed to.
Returns:
This pushed event.

popped

public Event popped(Calendar calendar)
This event was popped from a calendar. All its listeners will be informed to handle or execute this event. Then the list of event listeners will be cleared.

Specified by:
popped in interface Event
Parameters:
calendar - The calendar which popped this event.
Returns:
This popped event.

calendar

protected final Calendar calendar()
Get the calendar of this event.

Returns:
The calendar.

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.lang.Object
Returns:
The string.

hashCode

public final int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hash tables.

Overrides:
hashCode in class java.lang.Object
Returns:
A hash code value for this object.

equals

public final boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one. This method compares the events' time, priority and ID.

Overrides:
equals in class java.lang.Object
Parameters:
o - That object which is compared with this object.
Returns:
True, if this object is the same as that object.

compareTo

public final int compareTo(Event e)
Compares this object with the specified object for order. Implementation of Comparable interface. The events are compared in the order of the following conditions:
  1. Event with earlier time
  2. higher priority
  3. smaller ID first

Specified by:
compareTo in interface java.lang.Comparable<Event>
Specified by:
compareTo in class AbstractComparableObject<Event>
Parameters:
e - The event to be compared.
Returns:
A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
See Also:
Comparable.compareTo(Object)

isInitialized

public final boolean isInitialized()
Check, if this event has just been created.

Specified by:
isInitialized in interface Event
Returns:
True, if event has just been created.

isPushed

public final boolean isPushed()
Check, if this event has already been pushed to a calendar.

Specified by:
isPushed in interface Event
Returns:
True, if event has already been pushed.

isPopped

public final boolean isPopped()
Check, if this event has already been popped and executed.

Specified by:
isPopped in interface Event
Returns:
True, if event has already popped.

getEventListeners

public final java.util.Collection<EventListener> getEventListeners()
Get the unmodifiable collection of the event listeners for this event.

Specified by:
getEventListeners in interface Event
Returns:
The event listener collection.

addEventListener

public final void addEventListener(EventListener listener)
Add a model for this event. Each model that shall be informed about handling this event, has to be added to the model list of this event.

Specified by:
addEventListener in interface Event
Parameters:
listener - The model to handle the event.

removeEventListener

public final void removeEventListener(EventListener listener)
Remove a model for this event.

Specified by:
removeEventListener in interface Event
Parameters:
listener - The model to handle the event.

setId

public final void setId(Id id)
Set the event's ID. Each simulation element obtains during its registration at the calendar (pushing) a unique, increasing number for identification. If ID is already set, it will not be changed.

Specified by:
setId in interface SimObject
Parameters:
id - The ID.

getId

public final Id getId()
Retrieve the event's ID. Each simulation event obtains during its registration at the calendar (pushing) a unique, increasing number for identification.

Specified by:
getId in interface SimObject
Returns:
The ID.

setTime

public final void setTime(Time time)
Initialize the event's time. The event's priority must be set previous to its time.

Parameters:
time - The event's time.

getTime

public final Time getTime()
Retrieve the event's time.

Specified by:
getTime in interface Event
Returns:
The time of this event.

setPriority

public final void setPriority(int priority)
Initialize the event's priority. The event's priority must be set previous to its time.

Parameters:
priority - The event's priority.

getPriority

public final int getPriority()
Retrieve the event's priority. A higher priority corresponds to a greater integer value.

Specified by:
getPriority in interface Event
Returns:
The priority of this event.

inform

public boolean inform()
Request, if this event is an internal or external event. An internal event will not inform listeners of the calendars when pushed or popped. If this method is not overwritten by extending classes, all subclasses will be external by default.

Specified by:
inform in interface Event
Returns:
True, always.