at.ac.tuwien.infosys.sm4all.copal.api.event
Class BaseEvent

java.lang.Object
  extended by at.ac.tuwien.infosys.sm4all.copal.api.event.BaseEvent
Direct Known Subclasses:
ContextEvent

public class BaseEvent
extends java.lang.Object

Class which contains the meta-data for base events. This class is not thread safe.

Author:
fei, sanjin

Constructor Summary
protected BaseEvent(java.lang.String sourceID, java.util.Date timeStamp)
          Create instance of BaseEvent with specified source ID and time stamp.
 
Method Summary
 void append(UnprocessedAction... unprocessedActions)
          Append specified UnprocessedActions.
 boolean equals(java.lang.Object obj)
          Compare this BaseEvent to the specified Object.
 ContextEventAction getAction(int index)
          Return the ContextEventAction at specified index.
 ContextEventAction[] getActions()
          Return all currently added ContextEventActions.
 CurrentAction getCurrentAction()
          Return the CurrentAction.
 int getCurrentActionIndex()
          Return the index of CurrentAction or -1 if this BaseEvent was just created.
 int getNumberOfActions()
          Return the number of ContextEventActions.
 java.lang.String getSourceID()
          Return the source ID of this BaseEvent.
 java.util.Date getTimeStamp()
          Return the time stamp for this BaseEvent.
 boolean hasAction(java.lang.String name)
          Return if there is at least one ContextEventAction with specified name.
 int hashCode()
          Return hash code for this BaseEvent.
 void insert(int index, UnprocessedAction action)
          Insert specified UnprocessedAction at specified index.
 void nextAction()
          Move CurrentAction to next UnprocessedAction.
 void removeAction(int index)
          Remove the UnprocessedAction at specified index.
 void replace(int index, UnprocessedAction action)
          Replace the UnprocessedAction at specified index with specified UnprocessedAction.
protected  void set(ContextEventAction... actions)
          Remove all previously added ContextEventActions and add specified ContextEventActions.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BaseEvent

protected BaseEvent(java.lang.String sourceID,
                    java.util.Date timeStamp)
Create instance of BaseEvent with specified source ID and time stamp.

Parameters:
sourceID - the source ID of BaseEvent.
timeStamp - the time stamp for BaseEvent.
Throws:
java.lang.NullPointerException - if specified source ID or time stamp is null.
java.lang.IllegalArgumentException - if specified source ID is an empty or blank string.
Method Detail

getSourceID

public java.lang.String getSourceID()
Return the source ID of this BaseEvent.

Returns:
the source ID of this BaseEvent.

getTimeStamp

public java.util.Date getTimeStamp()
Return the time stamp for this BaseEvent.

Returns:
the time stamp for this BaseEvent.

getAction

public ContextEventAction getAction(int index)
Return the ContextEventAction at specified index.

Parameters:
index - the index of ContextEventAction.
Returns:
the ContextEventAction.

getActions

public ContextEventAction[] getActions()
Return all currently added ContextEventActions.

Returns:
all currently added ContextEventActions.

set

protected void set(ContextEventAction... actions)
Remove all previously added ContextEventActions and add specified ContextEventActions. This method will set the index of CurrentAction to the index of the CurrentAction in specified array of ContextEventActions.

Parameters:
actions - ContextEventActions.
Throws:
java.lang.NullPointerException - if specified array ContextEventActions or any ContextEventAction in the array is null.

getCurrentActionIndex

public int getCurrentActionIndex()
Return the index of CurrentAction or -1 if this BaseEvent was just created.

Returns:
the index of CurrentAction.

getCurrentAction

public CurrentAction getCurrentAction()
Return the CurrentAction.

Returns:
the CurrentAction or null if this BaseEvent. was just created or there are no more actions in the list.

hasAction

public boolean hasAction(java.lang.String name)
Return if there is at least one ContextEventAction with specified name.

Parameters:
name - the name of the ContextEventAction.
Returns:
if there is at least one ContextEventAction with specified name.

getNumberOfActions

public int getNumberOfActions()
Return the number of ContextEventActions.

Returns:
the number of ContextEventActions.

nextAction

public void nextAction()
Move CurrentAction to next UnprocessedAction.


append

public void append(UnprocessedAction... unprocessedActions)
Append specified UnprocessedActions.

Parameters:
unprocessedActions - the UnprocessedActions.
Throws:
java.lang.IllegalArgumentException - if all actions are processed (i.e. getCurrentActionIndex() points to the end of the actions).

insert

public void insert(int index,
                   UnprocessedAction action)
Insert specified UnprocessedAction at specified index.

Parameters:
index - the index at which the UnprocessedAction is inserted.
action - the UnprocessedAction.
Throws:
java.lang.IllegalArgumentException - if specified index is less than or equal to getCurrentActionIndex().

replace

public void replace(int index,
                    UnprocessedAction action)
Replace the UnprocessedAction at specified index with specified UnprocessedAction.

Parameters:
index - the index at which the UnprocessedAction is replaced.
action - the UnprocessedAction.
Throws:
java.lang.IllegalArgumentException - if specified index is less than or equal to getCurrentActionIndex() or is greater or equal than getNumberOfActions().

removeAction

public void removeAction(int index)
Remove the UnprocessedAction at specified index.

Parameters:
index - the index at which the UnprocessedAction is removed.
Throws:
java.lang.IllegalArgumentException - if specified index is less than or equal to getCurrentActionIndex().

hashCode

public int hashCode()
Return hash code for this BaseEvent. The hash code for a BaseEvent object is computed as:
 source ID * 31 + time stamp
 
using integer arithmetic.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this BaseEvent.

equals

public boolean equals(java.lang.Object obj)
Compare this BaseEvent to the specified Object. The result is true if and only if the argument is not null and is a BaseEvent object that has same source ID and time stamp as this BaseEvent.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the Object to compare this BaseEvent against.
Returns:
true if BaseEvents are equal; false otherwise.


Copyright © 2010 Distributed Systems Group, Vienna University of Technology. All Rights Reserved.