edu.berkeley.guir.ptk.notification
Class NotificationSetter

java.lang.Object
  extended byedu.berkeley.guir.ptk.PTK
      extended byedu.berkeley.guir.ptk.notification.NotificationSetter
Direct Known Subclasses:
AnyChangesNotificationSetter, DegreeChangeNotificationSetter, ExactMatchNotificationSetter, ThresholdNotificationSetter

public abstract class NotificationSetter
extends PTK

Notification setters must implement this abstract class. The method set determines which notification level the event should get and sets it. The data_id data field can be set to specify what data to check for in new events. For example, if set to PTKConstants.Volume_ID, then this notification setter will check the data field in the input event representing volume to determine the notification level. If the data_id field is not set, then the Notification Setter will check all of the event's data items when setting the notification level.

Author:
tmatthew

Field Summary
 java.lang.String[] data_id
          ID(s) of data to check for in the Event passed in.
 Translate translate
          Specifies how to translate any given data item - notification setter defaults only care about translating to a number.
 
Fields inherited from class edu.berkeley.guir.ptk.PTK
debug, MAX_DEBUG, MED_DEBUG, MIN_DEBUG, NO_DEBUG
 
Constructor Summary
NotificationSetter()
          Default constructor.
 
Method Summary
 void addMetadataIWant(Metadata mds)
          Performs a deep copy of the MetadataItems in the array passed in to the metadata_I_want data field.
 boolean canISetNotification(Event e)
          Compares the given event's metadata items to this Setter's metadata.
 Metadata[] getAllMetadata()
          Returns all Metadata objects that indicate all input events the notification setter can handle (used for connections to multiple inputs).
 Data[] getEventData(Event e)
          Returns the data from the event that the notification setter uses to determine how to set the notification.
 double[] getEventDataAsDouble(Event e)
          Returns the data from the event (converted to a double) that the notification setter uses to determine how to set the notification.
 Metadata getFirstMetadata()
          Returns only the first Metadata object; for notifiction setter that connect to only a single input, the first will be the ONLY Metadata object.
abstract  int set(Event e, History h)
          Sets the notification level of the given event.
 
Methods inherited from class edu.berkeley.guir.ptk.PTK
getMAX, getMED, getMIN, getNO, printDebug, printDebug, printError
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data_id

public java.lang.String[] data_id
ID(s) of data to check for in the Event passed in.


translate

public Translate translate
Specifies how to translate any given data item - notification setter defaults only care about translating to a number. If you are using some Data object that is not easily translated to a number (like a String or File), then you must subclass the Translate class and implement the method that translates that Data object to a number. Subclassing this class can also be used to define how an input event is abstracted.

Constructor Detail

NotificationSetter

public NotificationSetter()
Default constructor.

Method Detail

set

public abstract int set(Event e,
                        History h)
Sets the notification level of the given event. Notification setter classes that imlement this class must implement this method.

Parameters:
e - The event that may have its notification set.
h - The history of events that have been passed to this application.
Returns:
The notification level to which it set the evet, or PTKContants.NOTIFICATION_LEVEL_NOT_SET

getEventDataAsDouble

public double[] getEventDataAsDouble(Event e)
Returns the data from the event (converted to a double) that the notification setter uses to determine how to set the notification. If a valid data ID is set in the NotificationSetter.data_id field, the this method translates the corresponding Data object in the Event e to a double. Otherwise, this method gets all the Data objects in Event e and translates them all, and returns an array of doubles.

To perform the translation to a double, this method calls translate.toNumber(). To customize the way in which Data is converted to doubles, pass a custom Translate object into the NotificationSetter.

This method is used by the default threshold and degree change notification setters, because they must be able to quantify and order the data to determine if it is within a threshold or by how much it has changed.

Parameters:
e - The event containing the data for which notification will be set.

getEventData

public Data[] getEventData(Event e)
Returns the data from the event that the notification setter uses to determine how to set the notification. The first choice is to return the data with the id specified by NotificationSetter.data_id. If this data field is not set, then all the Data objects in the event are returned.

Parameters:
e - The event containing the data for which notification will be set.

addMetadataIWant

public void addMetadataIWant(Metadata mds)
Performs a deep copy of the MetadataItems in the array passed in to the metadata_I_want data field. Use this method instead of "=" so that multiple objects are not sharing the same array of MetadatItems.


getFirstMetadata

public Metadata getFirstMetadata()
Returns only the first Metadata object; for notifiction setter that connect to only a single input, the first will be the ONLY Metadata object.

Returns:

getAllMetadata

public Metadata[] getAllMetadata()
Returns all Metadata objects that indicate all input events the notification setter can handle (used for connections to multiple inputs).

Returns:

canISetNotification

public boolean canISetNotification(Event e)
Compares the given event's metadata items to this Setter's metadata. If this.metadata_I_want is included in the given event's metadata, then it returns true. This indicates that this Setter can set the notification for the event. Also checks data IDs if they are set.

Parameters:
e - Event