public class Event
extends java.util.EventObject
The Event
class provides methods to create events and
to retrieve information from events. The predefined system events are also
defined in this class.
Each event has a name, a typed value, a source and may have a message and
an information object. The source of the event is either system or another application.
The typed value must be one of long, double, boolean, or String
.
Events can be constructed from any primitive type but are converted to
one of the types above using the normal Java Language Specification
rules for type conversions (see [JLS]
Chapter 5, Conversions and Promotions).
The methods getInt
, getLong
,
getFloat
, getDouble
,
getBoolean
, getString
return the
value by converting the value to the type requested as defined in each method.
The method getValue
returns the value as an Object.
Some event names and values are defined within this class, other packages may define their own event names and values to be used with this class.
The information object supports a limited set of types to keep the
implementation simple. The valid types allowed for the info object is
restricted to: java.lang.String
, java.lang.Boolean
,
java.lang.Double
, java.lang.Long
, and
byte[]
.
The Event
class and EventManager
implementations MUST support passing the event name, value, message and info
object totaling at least 1024 bytes. Each character of the String objects,
including event name, value, and message is counted as two bytes. The number
of bytes counted for the primitive value types are:
boolean: 1,
double: 8,
long: 8.
Some system properties have values that may change at runtime. If
notification of changes to system properties is desired then the
specification of each such system property must define the associated event
of the same name. The system property event values are String
s
and will return the current value of the system property as the value of the
event.
The implementation MUST ensure that when the system property is set that the
corresponding event is posted. The event name for each such system property
MUST be returned from the
EventManager.getSystemEventNames
method.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
APPLICATION_RELAUNCH_PREFIX
To be used as an event name.
|
static java.lang.String |
AUDIO_MUTE
To be used as an event name.
|
static java.lang.String |
SYSTEM_STATE
To be used as an event name.
|
static java.lang.String |
SYSTEM_STATE_NORMAL
Valid value for
SYSTEM_STATE events. |
static java.lang.String |
SYSTEM_STATE_SHUTDOWN
Valid value for
SYSTEM_STATE events. |
static java.lang.String |
SYSTEM_STATE_STANDBY
Valid value for
SYSTEM_STATE events. |
static java.lang.String |
SYSTEM_STATE_STARTUP
Valid value for
SYSTEM_STATE events. |
static java.lang.String |
VOICE_CALL
Indicates whether there are voice calls currently active.
|
Constructor and Description |
---|
Event(java.lang.String event,
boolean value,
java.lang.String message,
java.lang.Object info)
Creates a new instance of
Event with a boolean
value. |
Event(java.lang.String event,
double value,
java.lang.String message,
java.lang.Object info)
Creates a new instance of
Event with a double
value. |
Event(java.lang.String event,
long value,
java.lang.String message,
java.lang.Object info)
Creates a new instance of
Event with a long
value. |
Event(java.lang.String event,
java.lang.String value,
java.lang.String message,
java.lang.Object info)
Creates a new instance of
Event with a String
value. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object object)
Checks if another object is "equal" to this one.
|
boolean |
getBoolean()
Gets the value as a
boolean . |
double |
getDouble()
Gets the value as a
double . |
float |
getFloat()
Gets the value as a
float . |
java.lang.Object |
getInfo()
Gets information regarding the event.
|
int |
getInt()
Gets the value as an
int . |
long |
getLong()
Gets the value as an
long . |
java.lang.String |
getMessage()
Gets the message for this event.
|
java.lang.String |
getName()
Gets the name of the event.
|
java.lang.Object |
getSource()
Gets the information about the source of this event.
|
java.lang.String |
getString()
Gets the value as a
String . |
long |
getTimestamp()
Gets the time when the event was posted.
|
java.lang.Object |
getValue()
Gets the value as a
java.lang.Object . |
int |
hashCode()
Gets the hash code value for this object.
|
java.lang.String |
toString()
Gets the value as a
String . |
public static final java.lang.String SYSTEM_STATE
Indicates the system state as a String
value.
Valid values are
SYSTEM_STATE_STARTUP
,
SYSTEM_STATE_NORMAL
,
SYSTEM_STATE_SHUTDOWN
, and
SYSTEM_STATE_STANDBY
.
Events for each system state are delivered when the
system enters the state. The current system state can
be queried with EventManager.getCurrent
.
When the system is initialized the STARTUP state is entered
and startup applications are automatically launched.
When the system is ready to begin running applications or resuming
from the standby state the NORMAL state is entered.
When the system is in a low power or standby state the
STANDBY state is entered.
When the system is shutting down applications the SHUTDOWN
state is entered.
public static final java.lang.String SYSTEM_STATE_NORMAL
SYSTEM_STATE
events.
Indicates the system is running applications normally.SYSTEM_STATE
,
Constant Field Valuespublic static final java.lang.String SYSTEM_STATE_STARTUP
SYSTEM_STATE
events.
Indicates the system is starting up.SYSTEM_STATE
,
Constant Field Valuespublic static final java.lang.String SYSTEM_STATE_SHUTDOWN
SYSTEM_STATE
events.
Indicates the system is shutting down.SYSTEM_STATE
,
Constant Field Valuespublic static final java.lang.String SYSTEM_STATE_STANDBY
SYSTEM_STATE
events.
Indicates the device is entering a potentially
low power state in which no applications are running.SYSTEM_STATE
,
Constant Field Valuespublic static final java.lang.String VOICE_CALL
boolean
value of true
indicates that there
are voice calls active while a value of false
indicates
that no voice calls are active.public static final java.lang.String AUDIO_MUTE
boolean
value of true
indicates all audio
output devices are muted and false
otherwise.public static final java.lang.String APPLICATION_RELAUNCH_PREFIX
true
.public Event(java.lang.String event, java.lang.String value, java.lang.String message, java.lang.Object info)
Event
with a String
value. The event name may be either a custom application specific event
name or one of the predefined system events.event
- The name of the event, not empty.value
- The String
value for this eventmessage
- The message text explaining the current event, or null
if this event has no message.info
- Additional information about this event, or null
for no information.java.lang.NullPointerException
- If event
or value
parameter is
null
.java.lang.IllegalArgumentException
- If the Java type of info
is not one of
the valid types or if the
event
parameter is an empty string.public Event(java.lang.String event, long value, java.lang.String message, java.lang.Object info)
Event
with a long
value. The event name may be either a custom application specific event
name or one of the predefined system events.event
- The name of the event, not empty.value
- The value
for this event;
the full range of long
values MUST be stored.message
- The message text explaining the current event, or null
if this event has no message.info
- Additional information about this event, or null
for no information.java.lang.NullPointerException
- If event
parameter is null
java.lang.IllegalArgumentException
- If the Java type of info
is not one of
the valid types or if the
event
parameter is an empty string.getLong()
,
getInt()
public Event(java.lang.String event, double value, java.lang.String message, java.lang.Object info)
Event
with a double
value. The event name may be either a custom application specific event
name or one of the predefined system events.event
- The name of the event, not empty.value
- The value
for this event;
the full range of double
values MUST be stored.message
- The message text explaining the current event, or null
if this event has no message.info
- Additional information about this event, or null
for no information.java.lang.NullPointerException
- If the event
parameter is null
.java.lang.IllegalArgumentException
- If the Java type of info
is not one of
the valid types or if the
event
parameter is an empty string.public Event(java.lang.String event, boolean value, java.lang.String message, java.lang.Object info)
Event
with a boolean
value. The event name may be either a custom application specific event
name or one of the predefined system events.event
- The name of the event, not empty.value
- The boolean
value for this event.message
- The message text explaining the current event, or null
if this event has no message.info
- Additional information about this event, or null
for no information.java.lang.NullPointerException
- If the event
parameter is null
.java.lang.IllegalArgumentException
- If the Java type of info
is not one of
the valid types or if the
event
parameter is an empty string.public java.lang.String getName()
public int hashCode()
java.lang.Object.hashcode
.hashCode
in class java.lang.Object
public boolean equals(java.lang.Object object)
Event
and
the event name, event typed value, and the message are all equal.
The additional information is ignored.equals
in class java.lang.Object
object
- an object to comparetrue
if the object is an instance of the same class
and the event name, event typed value, and the message are all equal.public java.lang.String getMessage()
null
if this event has no message.public java.lang.Object getInfo()
instanceof
operator or the object's Class
may be used to determine the type of the value.null
if there
is no further information about this event.public float getFloat() throws java.lang.NumberFormatException
float
.
Value | Convert to float |
---|---|
long | (float)value |
double | (float)value |
boolean | (value ? 1.0f : 0.0f) |
String | java.lang.Float.parseFloat(value) |
float
.java.lang.NumberFormatException
- If the value is a boolean
or can not be parsed as a
float
value.public double getDouble() throws java.lang.NumberFormatException
double
.
Value | Convert to double |
---|---|
long | (double)value |
double | value |
boolean | (value ? 1.0d : 0.0d) |
String | java.lang.Double.parseDouble(value) |
double
.java.lang.NumberFormatException
- If the value can not be parsed as a double
value.public int getInt() throws java.lang.NumberFormatException
int
.
Value | Convert to int |
---|---|
long | (int)value |
double | (int)value |
boolean | (value ? 1 : 0) |
String | java.lang.Integer.parseInt(value) |
int
.java.lang.NumberFormatException
- If the value can not be parsed as an int
value.public long getLong() throws java.lang.NumberFormatException
long
.
Value | Convert to long |
---|---|
long | value |
double | (long)value |
boolean | (value ? 1L : 0L) |
String | java.lang.Long.parseLong(value) |
long
.java.lang.NumberFormatException
- If the value can not be parsed as a long
value.public boolean getBoolean()
boolean
.
Value | Convert to boolean |
---|---|
long | (value == 0L ? false : true) |
double | (value == 0.0d ? false : true |
boolean | value |
String | value.equals("true") |
boolean
.public java.lang.Object getValue()
java.lang.Object
.
The value of the event is converted to an Object
depending
on the type of the value:
Value | Convert to Object |
---|---|
long | new java.lang.Long(value) |
double | new java.lang.Double(value) |
boolean | new java.lang.Boolean(value) |
String | new java.lang.String(value) |
Object
.public java.lang.String getString()
String
.
The value of the event is converted to a String depending
on the type of the value:
Value | Convert to String |
---|---|
long | java.lang.Long.toString() |
double | java.lang.Double.toString() |
boolean | java.lang.Boolean.toString() |
String | value |
String
.public java.lang.String toString()
String
.
The value of the event is using getString
.toString
in class java.util.EventObject
String
.public java.lang.Object getSource()
null
is returned.getSource
in class java.util.EventObject
MIDletIdentity
instance containing information
about the source of the event; null
if this
Event
was not posted by an application.MIDletIdentity
public long getTimestamp()
java.lang.System.currentTimeMillis
.Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. Use of this specification is subject to license terms.