|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjuglr.Message
juglr.Box
public class Box
Recommended Message
class for general purpose messaging.
A Box is a value container type that can hold one of:
Box
esBox
esJSonBoxReader
and JSonBoxParser
for this purpose.
JSonBoxReader
,
JSonBoxParser
,
Serialized FormNested Class Summary | |
---|---|
static class |
Box.Type
The allowed types for box values |
static class |
Box.TypeException
Thrown when invoking methods on a box of a type that does not admit the invoked method |
Constructor Summary | |
---|---|
Box(boolean val)
Create a Box to hold a boolean |
|
Box(Box.Type type)
Create a Box to hold a value of type type |
|
Box(double val)
Create a Box to hold a double |
|
Box(java.util.List<Box> val)
Create a Box to hold a list of boxes |
|
Box(long val)
Create a Box to hold a long |
|
Box(java.util.Map<java.lang.String,Box> val)
Create a Box to hold a map of string keys to Box values |
|
Box(java.lang.String val)
Create a Box to hold a String |
Method Summary | |
---|---|
Box |
add(boolean val)
Add a child to a Box of LIST type. |
Box |
add(Box box)
Add a child Box to a Box of LIST type. |
Box |
add(double val)
Add a child to a Box of LIST type. |
Box |
add(java.util.List<Box> val)
Add a child Box to a Box of LIST type. |
Box |
add(long val)
Add a child to a Box of LIST type. |
Box |
add(java.util.Map<java.lang.String,Box> val)
Add a child Box to a Box of LIST type. |
Box |
add(java.lang.String val)
Add a child Box to a Box of LIST type. |
Box |
addAll(java.util.Collection<Box> boxes)
Add a collection of child boxes to a box of LIST type. |
void |
checkType(Box.Type t)
Assert that this Box is of type t and throw a
Box.TypeException if it is not. |
static void |
checkType(Box m,
Box.Type t)
Assert that the Box m is of type t and throw a
Box.TypeException if it is not. |
boolean |
equals(java.lang.Object o)
|
Box |
get(int index)
Get the Box at index from a Box of LIST type. |
Box |
get(java.lang.String key)
Retrieve a child Box with key key from a Box of
MAP type. |
boolean |
getBoolean()
Get the boolean which is contained in this Box of BOOLEAN
type |
boolean |
getBoolean(int index)
|
boolean |
getBoolean(java.lang.String key)
|
boolean |
getBoolean(java.lang.String key,
boolean defaultVal)
|
double |
getFloat()
Get the double which is contained in this Box of FLOAT
type |
double |
getFloat(int index)
|
double |
getFloat(java.lang.String key)
|
double |
getFloat(java.lang.String key,
double defaultVal)
|
java.util.List<Box> |
getList()
Get the List which is contained in this Box of LIST type |
java.util.List<Box> |
getList(int index)
|
java.util.List<Box> |
getList(java.lang.String key)
|
java.util.List<Box> |
getList(java.lang.String key,
java.util.List<Box> defaultVal)
|
long |
getLong()
Get the long which is contained in this Box of INT type |
long |
getLong(int index)
|
long |
getLong(java.lang.String key)
|
long |
getLong(java.lang.String key,
long defaultVal)
|
java.util.Map<java.lang.String,Box> |
getMap()
Get the Map which is contained in this Box of MAP type |
java.util.Map<java.lang.String,Box> |
getMap(int index)
|
java.util.Map<java.lang.String,Box> |
getMap(java.lang.String key)
|
java.util.Map<java.lang.String,Box> |
getMap(java.lang.String key,
java.util.Map<java.lang.String,Box> defaultVal)
|
java.lang.String |
getString()
Get the String which is contained in this Box of STRING
type |
java.lang.String |
getString(int index)
|
java.lang.String |
getString(java.lang.String key)
|
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultVal)
|
Box.Type |
getType()
Get the type of the value stored in the box |
Box.Type |
getType(int index)
Get the value type of the box stored at position index of this
list type box. |
Box.Type |
getType(java.lang.String key)
Get the value type of the box stored with key key of this
map type box. |
java.io.Serializable |
getVal()
Get the raw value contained in this box |
boolean |
has(int index)
Return true if index is within the range of the
list contained in this box of LIST type |
boolean |
has(java.lang.String key)
Check if this box of map type has a child for the key key |
static Box |
newList()
Create a Box that holds an empty list |
static Box |
newMap()
Create a Box that holds an empty map of string keys to Box values |
Box |
put(java.lang.String key,
boolean val)
Associate a value with key in box of MAP type. |
Box |
put(java.lang.String key,
Box val)
Associate a key String with a child Box inside a Box of LIST type. |
Box |
put(java.lang.String key,
double val)
Associate a value with key in box of MAP type. |
Box |
put(java.lang.String key,
java.util.List<Box> val)
Associate a value with key in box of MAP type. |
Box |
put(java.lang.String key,
long val)
Associate a value with key in box of MAP type. |
Box |
put(java.lang.String key,
java.util.Map<java.lang.String,Box> val)
Associate a value with key in box of MAP type. |
Box |
put(java.lang.String key,
java.lang.String val)
Associate a value with key in box of MAP type. |
Box |
putAll(java.util.Map<java.lang.String,Box> map)
Import all key-value pairs from map into this Box (which
must be of the MAP type). |
int |
size()
Return the number of immediate child StructuredMessages of this Box |
byte[] |
toBytes()
Return a newly allocated byte array containing this box as JSON encoded in the default system encoding. |
java.lang.String |
toString()
String format the value contained in this box |
Methods inherited from class juglr.Message |
---|
getReplyTo, getSender, setReplyTo |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Box(Box.Type type)
type
type
- the value type to store in the boxpublic Box(long val)
long
val
- the value to store in the boxpublic Box(double val)
double
val
- the value to store in the boxpublic Box(boolean val)
boolean
val
- the value to store in the boxpublic Box(java.lang.String val)
String
val
- the value to store in the boxpublic Box(java.util.List<Box> val)
val
- the value to store in the boxpublic Box(java.util.Map<java.lang.String,Box> val)
val
- the value to store in the boxMethod Detail |
---|
public static Box newList()
public static Box newMap()
public Box.Type getType()
public Box.Type getType(int index)
index
of this
list type box.
index
- the index into the list stored by this box
index
of this box
Box.TypeException
- if this
is not of type LIST
public Box.Type getType(java.lang.String key)
key
of this
map type box.
key
- check box with this key
key
Box.TypeException
- if this
is not of type MAP
java.lang.NullPointerException
- if there is no box for key
public boolean has(java.lang.String key)
key
key
- the key to check
true
if there is a box for the given key
Box.TypeException
- if this
is not of type MAP
java.lang.NullPointerException
- if there is no box for key
public boolean has(int index)
true
if index
is within the range of the
list contained in this box of LIST
type
index
- the number to check
true
if and only if index
is a valid index into
the listpublic java.io.Serializable getVal()
public Box add(Box box)
this
.
box
- the Box to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(long val)
this
.
val
- the value to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(double val)
this
.
val
- the value to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(boolean val)
this
.
val
- the value to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(java.lang.String val)
this
.
val
- the value to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(java.util.List<Box> val)
this
.
val
- the list to append
this
Box.TypeException
- if this box is not of type LIST
public Box add(java.util.Map<java.lang.String,Box> val)
this
.
val
- the map to append
this
Box.TypeException
- if this box is not of type LIST
public Box addAll(java.util.Collection<Box> boxes)
LIST
type.
This method always returns this
.
boxes
- the collection of Box instances to add
this
Box.TypeException
- if this box is not of type LIST
public Box put(java.lang.String key, Box val)
LIST
type.
key
- the key to add val
underval
- the Box to associate with key
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, long val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, double val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, boolean val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, java.lang.String val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, java.util.List<Box> val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box put(java.lang.String key, java.util.Map<java.lang.String,Box> val)
key
in box of MAP
type.
key
- the key to associate val
withval
- the value to insert
this
Box.TypeException
- if this box is not of type MAP
public Box putAll(java.util.Map<java.lang.String,Box> map)
map
into this Box (which
must be of the MAP type).
map
- a
this
Box.TypeException
- if this box is not of type MAP
public long getLong()
long
which is contained in this Box of INT
type
Box.TypeException
- if this box is not of type INT
public long getLong(int index)
public long getLong(java.lang.String key)
public long getLong(java.lang.String key, long defaultVal)
public double getFloat()
double
which is contained in this Box of FLOAT
type
Box.TypeException
- if this box is not of type FLOAT
public double getFloat(int index)
public double getFloat(java.lang.String key)
public double getFloat(java.lang.String key, double defaultVal)
public boolean getBoolean()
boolean
which is contained in this Box of BOOLEAN
type
Box.TypeException
- if this box is not of type BOOLEAN
public boolean getBoolean(int index)
public boolean getBoolean(java.lang.String key)
public boolean getBoolean(java.lang.String key, boolean defaultVal)
public java.lang.String getString()
String
which is contained in this Box of STRING
type
Box.TypeException
- if this box is not of type STRING
public java.lang.String getString(int index)
public java.lang.String getString(java.lang.String key)
public java.lang.String getString(java.lang.String key, java.lang.String defaultVal)
public java.util.List<Box> getList()
List
which is contained in this Box of LIST
type
Box.TypeException
- if this box is not of type LIST
public java.util.List<Box> getList(int index)
public java.util.List<Box> getList(java.lang.String key)
public java.util.List<Box> getList(java.lang.String key, java.util.List<Box> defaultVal)
public java.util.Map<java.lang.String,Box> getMap()
Map
which is contained in this Box of MAP
type
Box.TypeException
- if this box is not of type MAP
public java.util.Map<java.lang.String,Box> getMap(int index)
public java.util.Map<java.lang.String,Box> getMap(java.lang.String key)
public java.util.Map<java.lang.String,Box> getMap(java.lang.String key, java.util.Map<java.lang.String,Box> defaultVal)
public Box get(int index)
index
from a Box of LIST type.
index
- the index into the list from which to retrieve the child
Box
index
public Box get(java.lang.String key)
key
from a Box of
MAP type.
key
- the key for the child Box to look up
null
public int size()
MAP
or LIST
public void checkType(Box.Type t)
t
and throw a
Box.TypeException
if it is not.
t
- the type that this Box must bepublic static void checkType(Box m, Box.Type t)
m
is of type t
and throw a
Box.TypeException
if it is not.
m
- the Box to check the type oft
- the type that this Box must bepublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public byte[] toBytes()
toString().getBytes()
in that
it avoids the intermediate string representation of the box.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |