|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.avis.client.Notification
public final class Notification
A notification sent via an Elvin router. A notification is a set of field name/value pairs. Field values may be one of the following types:
For efficiency, byte arrays passed in via the set () methods, constuctors, and clone () are not copied before being added to this object, nor are they copied before being returned by the get () methods. Please note that modifying a byte array that is part of a notification can cause undefined behaviour: treat all values of a notification as immutable.
Constructor Summary | |
---|---|
Notification()
Create an empty notification. |
|
Notification(Map<?,?> map)
Create a notification from the values in a map. |
|
Notification(Object... attributes)
Create a notification from an array of name/value pairs. |
|
Notification(Reader in)
Create an instance from an encoded notification read from a stream. |
|
Notification(String ntfnExpr)
Create an instance from an string encoded notification. |
Method Summary | ||
---|---|---|
Map<String,Object> |
asMap()
A live, unmodifiable Map view of this notification. |
|
void |
clear()
Remove all attributes from the notification. |
|
Notification |
clone()
|
|
Set<Map.Entry<String,Object>> |
entrySet()
Get the fields/values of this notification as a unmodifiable, live set of java.util.Map.Entry's that can be iterated over. |
|
boolean |
equals(Notification ntfn)
Compare two notifications. |
|
boolean |
equals(Object o)
|
|
Object |
get(String name)
Get a field value. |
|
double |
getDouble(String name)
Get a double value. |
|
int |
getInt(String name)
Get an integer value. |
|
long |
getLong(String name)
Get a long value. |
|
byte[] |
getOpaque(String name)
Get an opaque byte array value. |
|
String |
getString(String name)
Get a string value. |
|
boolean |
hasField(String name)
Test if this notification has a field with a given name. |
|
int |
hashCode()
|
|
boolean |
isEmpty()
True if size () == 0. |
|
Iterator<Map.Entry<String,Object>> |
iterator()
Create an iterator over this notification. |
|
Set<String> |
names()
The set of names in the notification. |
|
static void |
parse(Notification ntfn,
Reader in)
Parse an expression representing a notification and populate the given notification with the values. |
|
void |
remove(String name)
Remove (unset) a value. |
|
|
require(String name,
Class<E> type)
Shortcut to get a non-null value of specified type, or generate an exception. |
|
void |
set(String name,
byte[] value)
Set an opaque byte array value. |
|
void |
set(String name,
double value)
Set a double value. |
|
void |
set(String name,
int value)
Set an integer value. |
|
void |
set(String name,
long value)
Set a long value. |
|
void |
set(String name,
Object value)
Set a field value. |
|
void |
set(String name,
String value)
Set a string value. |
|
void |
setAll(Map<?,?> map)
Copy all values in a map into this notification. |
|
int |
size()
The number of name/value pairs in the notification. |
|
String |
toString()
Generate a string value of the notification. |
|
Collection<Object> |
values()
The set of values in the notification. |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Notification()
public Notification(Object... attributes) throws IllegalArgumentException
IllegalArgumentException
- if attributes do not represent a
valid notification.public Notification(Map<?,?> map) throws IllegalArgumentException
map
- The map to copy.
IllegalArgumentException
- if one of the map values is not
a valid type.public Notification(String ntfnExpr) throws InvalidFormatException
parse(Notification, Reader)
.
InvalidFormatException
public Notification(Reader in) throws IOException, InvalidFormatException
parse(Notification, Reader)
.
IOException
InvalidFormatException
Method Detail |
---|
public static void parse(Notification ntfn, Reader in) throws IOException, InvalidFormatException
ec
and
ep
utilities. For example:
An-Int32: 42 An-Int64: 24L A-Real64: 3.14 String: "String with a \" in it" Opaque: [01 02 0f ff] A field with a \: in it: 1The parser ignores lines starting with "$" and stops on end of stream or "---".
ntfn
- The notification to add values to.in
- The source to read the expression from.
IOException
- If reader throws an IO exception.
InvalidFormatException
- If there is an error in the format
of the expression. The notification may contain a
partial set of values already successfully read.public void clear()
public Notification clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public String toString()
parse(Notification, Reader)
for an example.
toString
in class Object
Text.formatNotification(Map)
public boolean hasField(String name)
public Set<String> names()
public Collection<Object> values()
public Map<String,Object> asMap()
public Set<Map.Entry<String,Object>> entrySet()
iterator()
public Iterator<Map.Entry<String,Object>> iterator()
iterator
in interface Iterable<Map.Entry<String,Object>>
public boolean equals(Object o)
equals
in class Object
public boolean equals(Notification ntfn)
public int hashCode()
hashCode
in class Object
public boolean isEmpty()
public int size()
public void setAll(Map<?,?> map)
map
- The map to copy.
IllegalArgumentException
- if a key in the map is not a
string, or a value is not a string, integer,
long, double or byte array. Some values may
already have been added to the notification.public void set(String name, Object value) throws IllegalArgumentException
name
- The field name.value
- The value, or null to clear field.
IllegalArgumentException
- if value is not a string,
integer, long, double or byte array.public void set(String name, int value)
name
- The field name.value
- The value.set(String, Object)
public void set(String name, long value)
name
- The field name.value
- The value.set(String, Object)
public void set(String name, double value)
name
- The field name.value
- The value.set(String, Object)
public void set(String name, String value)
name
- The field name.value
- The value.set(String, Object)
public void set(String name, byte[] value)
name
- The field name.value
- The value.set(String, Object)
public void remove(String name)
name
- the field name.public Object get(String name)
name
- The field name.
public String getString(String name) throws IllegalArgumentException
name
- The field name.
IllegalArgumentException
- if value is not a string.public int getInt(String name) throws IllegalArgumentException
name
- The field name.
IllegalArgumentException
- if value is not an integer or is null.public long getLong(String name) throws IllegalArgumentException
name
- The field name.
IllegalArgumentException
- if value is not a long or is null.public double getDouble(String name) throws IllegalArgumentException
name
- The field name.
IllegalArgumentException
- if value is not a double or is null.public byte[] getOpaque(String name) throws IllegalArgumentException
name
- The field name.
IllegalArgumentException
- if value is not a byte array.public <E> E require(String name, Class<E> type) throws IllegalArgumentException
name
- The field name.type
- The required type.
IllegalArgumentException
- if there is no value for the
field or the value is not the required type.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |