- All Implemented Interfaces:
JSOps
- Direct Known Subclasses:
ExpressionParser.ESPObject
,NJSObject
null
. The types of the
values that can be inserted into this object are JSObject
,
JSArray
, Boolean
, Number
, and String
.
the value null
. This class represents an object
with values that are associated with keys.
The class JSUtilities.JSON
can be used to
create instances of JSObject
and JSArray
,
and instances of these two classes in turn can be used
to configure a named-object factory, which can then
create a named object.
This class is based on Map
(a subset of that
Map's
methods), but with some run-time type
checking. In addition to primitive types (boolean numbers, and
strings), entries in the map can be other instances of this class or
instances of JSArray
, allowing trees or directed graphs to
be constructed. Iterators will provide the keys in the order in which
they were inserted.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(String key) Determine if a key exists for this object.entrySet()
Get an entry set for this object, each containing a key, value pair.Get the object associated with a key for this map.<T> T
Get the object associated with a key for this map, cast to a specified type.long
identity()
Get an integer identifying an instance of a class.keySet()
Get a set of the keys for this objectInsert a boolean value into this map.Insert a number into this map.Put an object into this map.Insert a string into this map.Insert an instance ofJSArray
into this map.Insert an instance ofJSObject
into this map.Insert any object.Remove the value associated with a keyint
size()
Get the number of elements contained in this object.toKeyMap()
Create the key map equivalent to this object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.bzdev.util.JSOps
nextIdentity
-
Constructor Details
-
JSObject
public JSObject()Constructor. -
JSObject
Constructor sharing the same tables. This is used byNJSObject
.- Parameters:
base
- the JSObject whose tables should be used
-
-
Method Details
-
identity
public long identity()Description copied from interface:JSOps
Get an integer identifying an instance of a class. -
put
Insert an instance ofJSObject
into this map.- Parameters:
key
- the keyobject
- another instance ofJSObject
providing the value for the key- Returns:
- the previous object; null if there was none
-
put
Insert an instance ofJSArray
into this map.- Parameters:
key
- the keyarray
- the value- Returns:
- the previous object; null if there was none
-
put
Insert a number into this map.- Parameters:
key
- the keyvalue
- the value- Returns:
- the previous object; null if there was none
-
put
Insert a string into this map.- Parameters:
key
- the keystring
- the string- Returns:
- the previous object; null if there was none
-
put
Insert a boolean value into this map.- Parameters:
key
- the keyvalue
- the boolean value (true or false)- Returns:
- the previous object; null if there was none
-
put
Put an object into this map. The object may be null. If it is not null, it may be an instance ofString
,Boolean
,Number
,JSArray
, orJSObject
.- Parameters:
key
- the keyobject
- the object- Returns:
- the previous object; null if there was none
- Throws:
IllegalArgumentException
-
putObject
Insert any object. When this method is used, the object may not be suitable for use with YAML or JSON, and may not work properly withtoKeyMap()
.- Parameters:
key
- the key for this entryobject
- the object to store for the specified key- Returns:
- the previous object; null if there was none
-
size
public int size()Get the number of elements contained in this object. -
keySet
Get a set of the keys for this object- Returns:
- a set of keys
-
entrySet
Get an entry set for this object, each containing a key, value pair.- Returns:
- the entry set
-
containsKey
Determine if a key exists for this object.- Parameters:
key
- the key- Returns:
- true if the key has a value; false otherwise.
-
remove
Remove the value associated with a key- Parameters:
key
- the key- Returns:
- the value removed; null if there is none
-
get
Get the object associated with a key for this map.- Parameters:
key
- the key- Returns:
- the value for the specified key
-
get
Get the object associated with a key for this map, cast to a specified type.- Type Parameters:
T
- the type for the argumentclasz
- Parameters:
key
- the keyclasz
- the class of the object that will be returned.- Returns:
- the value for the specified key
-
toKeyMap
Create the key map equivalent to this object. This method returns a key map containing the same keyword-value pairs, but with values that are instances of JSArray converted to key-map lists. If an element in the list is not an instance of JSObject, that element is replaced with a key map containing a single entry: one whose key is the key corresponding to the JSArray, and whose value is the list element. If the element in the list is a JSObject, that JSObject is converted to a key list (by calling this method).The single-entry maps are inserted in those cases where an entry in a list would be another list.
If creating a JSON representation of this object, the key map should be modified to properly quote strings.
- Returns:
- the key map
- Throws:
JSArray.ConversionException
- aJSArray
contained anotherJSArray
- See Also:
-