unsw.cse.mica.tools.timer
Class TimerEvent

java.lang.Object
  extended by unsw.cse.mica.tools.timer.TimerEvent
All Implemented Interfaces:
java.lang.Comparable

public class TimerEvent
extends java.lang.Object
implements java.lang.Comparable

A timer event. Each event consists of the following information:

Author:
jhw

Constructor Summary
TimerEvent(java.lang.String type, java.lang.String name, long time)
          Create a new one-off event of type type with name name and firing time time.
TimerEvent(java.lang.String type, java.lang.String name, long time, long period)
          Create a new recurring event of type type with name name, firing time time and a delay of period ms between firings.
TimerEvent(java.lang.String type, java.lang.String name, long time, long period, int count)
          Create a new recurring event of type type with name name, firing time time and a delay of period ms between firings.
 
Method Summary
 boolean addSlot(java.lang.String name, java.util.List value)
          Add a data slot to the event's map
 boolean addSlot(java.lang.String name, java.lang.String value)
          Add a data slot to the event's map
 int compareTo(java.lang.Object o)
          Compare two events, ordering them by their firing time.
 void decCount()
          Decrement the current count.
 int getCount()
          Get the count, the number of times this event is still listed to fire.
 java.lang.String getName()
          Get the name of the current event
 java.util.Iterator getSlotIterator()
          Get an iterator over the slots (each item is a Map.Entry object)
 long getTime()
          Get the next firing time for this event.
 java.lang.String getType()
          Get the type of the current event
 boolean hasSlots()
          Does the event have any data in its map?
 void incTime()
          Increment the firing time for this event by the period.
 java.lang.String toString()
          Return a string representation of this event.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TimerEvent

public TimerEvent(java.lang.String type,
                  java.lang.String name,
                  long time)
Create a new one-off event of type type with name name and firing time time.


TimerEvent

public TimerEvent(java.lang.String type,
                  java.lang.String name,
                  long time,
                  long period)
Create a new recurring event of type type with name name, firing time time and a delay of period ms between firings. The event will keep firing until explicitly stopped.


TimerEvent

public TimerEvent(java.lang.String type,
                  java.lang.String name,
                  long time,
                  long period,
                  int count)
Create a new recurring event of type type with name name, firing time time and a delay of period ms between firings. The event will file count times unless explicitly stopped at an earlier point.

Method Detail

getType

public java.lang.String getType()
Get the type of the current event


getName

public java.lang.String getName()
Get the name of the current event


addSlot

public boolean addSlot(java.lang.String name,
                       java.util.List value)
Add a data slot to the event's map

Parameters:
name -
value -

addSlot

public boolean addSlot(java.lang.String name,
                       java.lang.String value)
Add a data slot to the event's map

Parameters:
name -
value -

hasSlots

public boolean hasSlots()
Does the event have any data in its map?


getCount

public int getCount()
Get the count, the number of times this event is still listed to fire. If the event is set to fire indefinitely, -1 is returned.


decCount

public void decCount()
Decrement the current count. Only has an effect if the count is > 0.


getTime

public long getTime()
Get the next firing time for this event.


incTime

public void incTime()
Increment the firing time for this event by the period. Used for recurring events to move to the next firing time.


getSlotIterator

public java.util.Iterator getSlotIterator()
Get an iterator over the slots (each item is a Map.Entry object)


compareTo

public int compareTo(java.lang.Object o)
Compare two events, ordering them by their firing time.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Return a string representation of this event.

Overrides:
toString in class java.lang.Object