Class ModelNode
- All Implemented Interfaces:
Externalizable,Serializable,Cloneable
A node can be of any type specified in the ModelType enumeration. The type can
be queried via getType() and updated via any of the set*() methods. The
value of the node can be acquired via the as<type>() methods, where <type> is
the desired value type. If the type is not the same as the node type, a conversion is attempted between
the types.
A node can be made read-only by way of its protect() method, which will prevent
any further changes to the node or its sub-nodes.
Instances of this class are not thread-safe and need to be synchronized externally.
- Author:
- David M. Lloyd, Richard Opalka
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newModelNodewith an undefined value.ModelNode(boolean value) Creates a newModelNodewith the givenvalue.ModelNode(byte[] value) Creates a newModelNodewith the givenvalue.ModelNode(double value) Creates a newModelNodewith the givenvalue.ModelNode(int value) Creates a newModelNodewith the givenvalue.ModelNode(long value) Creates a newModelNodewith the givenvalue.Creates a newModelNodewith the givenvalue.ModelNode(BigDecimal value) Creates a newModelNodewith the givenvalue.ModelNode(BigInteger value) Creates a newModelNodewith the givenvalue.Creates a newModelNodewith the givenvalue.ModelNode(ValueExpression value) Creates a newModelNodewith the givenvalue. -
Method Summary
Modifier and TypeMethodDescriptionadd()Add a node to the end of this node's value list and return it.add(boolean newValue) Add the given value to the end of this node's value list.add(byte[] newValue) Add the given value to the end of this node's value list.add(double newValue) Add the given value to the end of this node's value list.add(int newValue) Add the given value to the end of this node's value list.add(long newValue) Add the given value to the end of this node's value list.Add the given value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.add(String propertyName, BigDecimal propertyValue) Add a property with the given name and value to the end of this node's value list.add(String propertyName, BigInteger propertyValue) Add a property with the given name and value to the end of this node's value list.Add a property with the given name and value to the end of this node's value list.add(String propertyName, ValueExpression propertyValue) Add a property with the given name and value to the end of this node's value list.add(BigDecimal newValue) Add the given value to the end of this node's value list.add(BigInteger newValue) Add the given value to the end of this node's value list.Add a copy of the given value to the end of this node's value list.Add a property to the end of this node's value list.add(ValueExpression newValue) Add the given value to the end of this node's value list.Add a node of typeModelType.LISTto the end of this node's value list and return it.Add a node of typeModelType.OBJECTto the end of this node's value list and return it.addExpression(String newValue) Deprecated.Get the value of this node as aBigDecimal.Get the value of this node as aBigInteger.booleanGet the value of this node as aboolean.booleanasBoolean(boolean defVal) Get the value of this node as aboolean.byte[]asBytes()Get the value of this node as a byte array.byte[]Get the value of this node as a byte array ornullif this node is notdefined.doubleasDouble()Get the value of this node as adouble.doubleasDouble(double defVal) Get the value of this node as andouble.Get the value of this node as an expression.intasInt()Get the value of this node as anint.intasInt(int defVal) Get the value of this node as anint.asList()Get the list of entries contained in this object.longasLong()Get the value of this node as along.longasLong(long defVal) Get the value of this node as along.asObject()Get a copy of this value as an object.Get the value of this node as a property.Get the value of this node as a property list.asPropertyList(List<Property> defaultValue) Get the value of this node as a property list.Get the value of this node as a property list.asString()Get the value as a string.Get the value as a string.Get the value as a string ornullif this node is notdefined.asType()Get the value of this node as a type, expressed using theModelTypeenum.clear()Clear this node's value and change its type toModelType.UNDEFINED.clone()Clone this model node.booleanDetermine whether this object is equal to another.booleanDetermine whether this object is equal to another.static ModelNodefromBase64(InputStream stream) Reads base64 data from the passed stream, and deserializes the decoded result.static ModelNodefromBase64String(String encoded) Reads base64 data from the passed string, and deserializes the decoded result.static ModelNodefromJSONStream(InputStream stream) Get a model node from a JSON text representation of the model node.static ModelNodefromJSONString(String input) static ModelNodefromStream(InputStream stream) Get a model node from a text representation of the model node.static ModelNodefromString(String input) Get a model node from a string representation of the model node.get(int index) Get the child of this node with the given index.Get the child of this node with the given name.Recursively get the children of this node with the given names.getType()Get the current type of this node.booleanhas(int index) Determine whether this node has a child with the given index.booleanDetermine whether this node has a child with the given name.booleanRecursively determine whether this node has children with the given names.booleanhasDefined(int index) Determine whether this node has a defined child with the given index.booleanhasDefined(String key) Determine whether this node has a defined child with the given name.booleanhasDefined(String... names) Recursively determine whether this node has defined children with the given names.inthashCode()Get the hash code of this node object.insert(int index) Insert a node at provided index of this node's value list and return it.insert copy of the given value to provided index of this node's value list.booleanDetermine whether this node is defined.booleanReturns whether this node has beenprotected.keys()Get the set of keys contained in this object.voidprotect()Prevent further modifications to this node and its sub-nodes.voidRead this node's content in binary format from the given source.voidRead this node's content in binary format from the given source.voidRead this node's content in binary format from the given source.voidRead this node's content in binary format from the given source.remove(int index) Remove a child of this list, returning the child.Remove a child of this node, returning the child.require(int index) Require the existence of a child of this node with the given index, returning the child.Require the existence of a child of this node with the given name, returning the child.resolve()Return a copy of this model node, with all values of typeModelType.EXPRESSIONlocally resolved.set(boolean newValue) Change this node's value to the given value.set(byte[] newValue) Change this node's value to the given value.set(double newValue) Change this node's value to the given value.set(int newValue) Change this node's value to the given value.set(long newValue) Change this node's value to the given value.Change this node's value to the given value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.set(String propertyName, BigDecimal propertyValue) Change this node's value to a property with the given name and value.set(String propertyName, BigInteger propertyValue) Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.Change this node's value to a property with the given name and value.set(String propertyName, ValueExpression propertyValue) Change this node's value to a property with the given name and value.set(BigDecimal newValue) Change this node's value to the given value.set(BigInteger newValue) Change this node's value to the given value.set(Collection<ModelNode> newValue) Change this node's value to a list whose values are copied from the given collection.Change this node's value to the given value.Change this node's value to the given value.Change this node's value to the given value.set(ValueExpression newValue) Change this node's value to the given value.Change this node's value to an empty list.Change this node's value to an empty object.setExpression(String newValue) Deprecated.Useset(ValueExpression)instead.setExpression(String propertyName, String propertyValue) Deprecated.Useset(String,ValueExpression)instead.toJSONString(boolean compact) Get a JSON string representation of this model node, formatted nicely, if requested.toString()Get a human-readable string representation of this model node, formatted nicely (possibly on multiple lines).voidwriteBase64(OutputStream stream) Encodes the serialized representation in base64 form and writes it to the specified output stream.voidwriteExternal(DataOutput out) Write this node's content in binary format to the given target.voidWrite this node's content in binary format to the given target.voidWrite this node's content in binary format to the given target.voidWrite this node's content in binary format to the given target.voidwriteJSONString(PrintWriter writer, boolean compact) Output the JSON string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.voidwriteString(PrintWriter writer, boolean compact) Output the DMR string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.
-
Field Details
-
TRUE
-
FALSE
-
ZERO
-
ZERO_LONG
-
-
Constructor Details
-
ModelNode
public ModelNode()Creates a newModelNodewith an undefined value. -
ModelNode
Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
ModelNode
Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
ModelNode
public ModelNode(boolean value) Creates a newModelNodewith the givenvalue.- Parameters:
value- the value.
-
ModelNode
public ModelNode(byte[] value) Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
ModelNode
public ModelNode(double value) Creates a newModelNodewith the givenvalue.- Parameters:
value- the value.
-
ModelNode
public ModelNode(int value) Creates a newModelNodewith the givenvalue.- Parameters:
value- the value.
-
ModelNode
public ModelNode(long value) Creates a newModelNodewith the givenvalue.- Parameters:
value- the value.
-
ModelNode
Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
ModelNode
Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
ModelNode
Creates a newModelNodewith the givenvalue.- Parameters:
value- the value. Cannot benull- Throws:
IllegalArgumentException- ifvalueisnull
-
-
Method Details
-
protect
public void protect()Prevent further modifications to this node and its sub-nodes. Note that copies of this node made after this method call will not be protected. -
isProtected
public boolean isProtected()Returns whether this node has beenprotected.- Returns:
trueifprotect()has been invoked on this node
-
asLong
Get the value of this node as along. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the long value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asLong
public long asLong(long defVal) Get the value of this node as along. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Parameters:
defVal- the default value to return if this node is notdefined- Returns:
- the long value
- Throws:
NumberFormatException- if this node'stypeisModelType.STRINGand a numeric conversion of the string value is not possibleIllegalArgumentException- if this node'stypeis one where no numeric conversion is possible
-
asLongOrNull
Get the value of this node as aLong, ornullif this node is notdefined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the long value or
null - Throws:
NumberFormatException- if this node'stypeisModelType.STRINGand a numeric conversion of the string value is not possibleIllegalArgumentException- if this node'stypeis one where no numeric conversion is possible
-
asInt
Get the value of this node as anint. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the int value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asInt
public int asInt(int defVal) Get the value of this node as anint. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Parameters:
defVal- the default value to return if this node is notdefined- Returns:
- the int value
- Throws:
NumberFormatException- if this node'stypeisModelType.STRINGand a numeric conversion of the string value is not possibleIllegalArgumentException- if this node'stypeis one where no numeric conversion is possible
-
asIntOrNull
Get the value of this node as anint, ornullif this node is notdefined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the int value or
null - Throws:
IllegalArgumentException- if no conversion is possible
-
asBoolean
Get the value of this node as aboolean. Collection types returntruefor non-empty collections. Numerical types returntruefor non-zero values.- Returns:
- the boolean value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asBoolean
public boolean asBoolean(boolean defVal) Get the value of this node as aboolean. Collection types returntruefor non-empty collections. Numerical types returntruefor non-zero values.- Parameters:
defVal- the default value to return if this node is notdefined- Returns:
- the boolean value
- Throws:
IllegalArgumentException- if this node'stypeis one where no numeric conversion is possible or if the type isModelType.STRINGand the string value is not equal, ignoring case, to the literaltrueorfalse
-
asBooleanOrNull
Get the value of this node as aboolean, ornullif this node is notdefined. Collection types returntruefor non-empty collections. Numerical types returntruefor non-zero values.- Returns:
- the boolean value or
null - Throws:
IllegalArgumentException- if no conversion is possible
-
asString
Get the value as a string. This is the literal value of this model node. More than one node type may yield the same value for this method.- Returns:
- the string value. A node that is not
definedreturns the literal stringundefined
-
asString
Get the value as a string. This is the literal value of this model node. More than one node type may yield the same value for this method.- Parameters:
defVal- the default value to return if this node is notdefined- Returns:
- the string value.
-
asStringOrNull
Get the value as a string ornullif this node is notdefined. This is the literal value of this model node. More than one node type may yield the same value for this method.- Returns:
- the string value or
null
-
asDouble
Get the value of this node as adouble. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the double value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asDouble
public double asDouble(double defVal) Get the value of this node as andouble. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Parameters:
defVal- the default value to return if this node is notdefined- Returns:
- the int value
- Throws:
NumberFormatException- if this node'stypeisModelType.STRINGand a numeric conversion of the string value is not possibleIllegalArgumentException- if this node'stypeis one where no numeric conversion is possible
-
asDoubleOrNull
Get the value of this node as adoubleornullif this node is notdefined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the double value or
null - Throws:
IllegalArgumentException- if no conversion is possible
-
asType
Get the value of this node as a type, expressed using theModelTypeenum. The string value of this node must be convertible to a type.- Returns:
- the
ModelTypevalue - Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asBigDecimal
Get the value of this node as aBigDecimal. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the
BigDecimalvalue - Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asBigDecimalOrNull
Get the value of this node as aBigDecimalornullif this node is notdefined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the
BigDecimalvalue ornull - Throws:
IllegalArgumentException- if no conversion is possible
-
asBigInteger
Get the value of this node as aBigInteger. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the
BigIntegervalue - Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asBigIntegerOrNull
Get the value of this node as aBigIntegerornullif this node is notdefined. Collection types will return the size of the collection for this value. Other types may attempt a string conversion.- Returns:
- the
BigIntegervalue ornull - Throws:
IllegalArgumentException- if no conversion is possible
-
asBytes
Get the value of this node as a byte array. Strings and string-like values will return the UTF-8 encoding of the string. Numerical values will return the byte representation of the number.- Returns:
- the bytes
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asBytesOrNull
Get the value of this node as a byte array ornullif this node is notdefined. Strings and string-like values will return the UTF-8 encoding of the string. Numerical values will return the byte representation of the number.- Returns:
- the bytes or
null - Throws:
IllegalArgumentException- if no conversion is possible
-
asExpression
Get the value of this node as an expression.- Returns:
- the expression
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asProperty
Get the value of this node as a property. Object values will return a property if there is exactly one property in the object. List values will return a property if there are exactly two items in the list, and if the first is convertible to a string.- Returns:
- the property value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asPropertyList
Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.- Returns:
- the property list value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
asPropertyListOrEmpty
Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.- Returns:
- the property list value or an empty list if not
defined. - Throws:
IllegalArgumentException- if no conversion is possible
-
asPropertyList
Get the value of this node as a property list. Object values will return a list of properties representing each key-value pair in the object. List values will return all the values of the list, failing if any of the values are not convertible to a property value.- Parameters:
defaultValue- the value to return if notdefined.- Returns:
- the property list value or the specified default value if not
defined. - Throws:
IllegalArgumentException- if no conversion is possible
-
asObject
Get a copy of this value as an object. Object values will simply copy themselves as by theclone()method. Property values will return a single-entry object whose key and value are copied from the property key and value. List values will attempt to interpolate the list into an object by iterating each item, mapping each property into an object entry and otherwise taking pairs of list entries, converting the first to a string, and using the pair of entries as a single object entry. If an object key appears more than once in the source object, the last key takes precedence.- Returns:
- the object value
- Throws:
IllegalArgumentException- if this node is notdefinedor if no conversion is possible
-
isDefined
public boolean isDefined()Determine whether this node is defined. Equivalent to the expression:getType() != ModelType.UNDEFINED.- Returns:
trueif this node's value is defined
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
setExpression
Deprecated.Useset(ValueExpression)instead.Change this node's value to the given expression value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value. The value is copied from the parameter.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to the given value.- Parameters:
newValue- the new value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
setExpression
Deprecated.Useset(String,ValueExpression)instead.Change this node's value to a property with the given name and expression value.- Parameters:
propertyName- the property namepropertyValue- the property expression value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a property with the given name and value.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
-
set
Change this node's value to a list whose values are copied from the given collection.- Parameters:
newValue- the list value- Returns:
- this node
-
setEmptyList
Change this node's value to an empty list.- Returns:
- this node
-
setEmptyObject
Change this node's value to an empty object.- Returns:
- this node
-
clear
Clear this node's value and change its type toModelType.UNDEFINED.- Returns:
- this node
-
get
Get the child of this node with the given name. If no such child exists, create it. If the node is undefined, it will be initialized to be of typeModelType.OBJECT.When called on property values, the name must match the property name.
- Parameters:
name- the child name- Returns:
- the child
- Throws:
IllegalArgumentException- if this node does not support getting a child with the given name
-
require
Require the existence of a child of this node with the given name, returning the child. If no such child exists, an exception is thrown.When called on property values, the name must match the property name.
- Parameters:
name- the child name- Returns:
- the child
- Throws:
NoSuchElementException- if the element does not exist
-
remove
Remove a child of this node, returning the child. If no such child exists,nullis returned.When called on property values, the name must match the property name.
- Parameters:
name- the child name- Returns:
- the child, or
nullif no child with the givennameexists - Throws:
NoSuchElementException
-
remove
Remove a child of this list, returning the child. If no such child exists, an exception is thrown.When called on property values, the name must match the property name.
- Parameters:
index- the child index- Returns:
- the child
- Throws:
NoSuchElementException- if the element does not exist
-
get
Get the child of this node with the given index. If no such child exists, create it (adding list entries as needed). If the node is undefined, it will be initialized to be of typeModelType.LIST.When called on property values, the index must be zero.
- Parameters:
index- the child index- Returns:
- the child
- Throws:
IllegalArgumentException- if this node does not support getting a child with the given index
-
require
Require the existence of a child of this node with the given index, returning the child. If no such child exists, an exception is thrown.When called on property values, the index must be zero.
- Parameters:
index- the child index- Returns:
- the child
- Throws:
NoSuchElementException- if the element does not exist
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
addExpression
Deprecated.Useadd(ValueExpression)instead.Add the given expression to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a copy of the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
insert
insert copy of the given value to provided index of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST. An index equal to the current number of child elements held by this node is allowed (thus adding a child) but an index greater than that is not allowed (i.e. adding intervening elements is not supported.)- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IndexOutOfBoundsException- ifindexis greater than zero and is greater than the number of child nodes currently stored in this nodeIllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add the given value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
newValue- the new value to add- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
property- the property- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a property with the given name and value to the end of this node's value list. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Parameters:
propertyName- the property namepropertyValue- the property value- Returns:
- this node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
add
Add a node to the end of this node's value list and return it. If the node is undefined, it will be initialized to be of typeModelType.LIST.- Returns:
- the new node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
insert
Insert a node at provided index of this node's value list and return it. If the node is undefined, it will be initialized to be of typeModelType.LIST. An index equal to the current number of child elements held by this node is allowed (thus adding a child) but an index greater than that is not allowed (i.e. adding intervening elements is not supported.)- Parameters:
index- where in list to put it- Returns:
- the new node
- Throws:
IndexOutOfBoundsException- ifindexis greater than zero and is greater than the number of child nodes currently stored in this nodeIllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
addEmptyList
Add a node of typeModelType.LISTto the end of this node's value list and return it. If this node is undefined, it will be initialized to be of typeModelType.LIST.- Returns:
- the new node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
addEmptyObject
Add a node of typeModelType.OBJECTto the end of this node's value list and return it. If this node is undefined, it will be initialized to be of typeModelType.LIST.- Returns:
- the new node
- Throws:
IllegalArgumentException- if this node isdefinedand itstypeis notModelType.LIST
-
has
public boolean has(int index) Determine whether this node has a child with the given index. Property node types always contain exactly one value.- Parameters:
index- the index- Returns:
trueif there is a (possibly undefined) node at the given index
-
has
Determine whether this node has a child with the given name. Property node types always contain exactly one value with a key equal to the property name.- Parameters:
key- the name- Returns:
trueif there is a (possibly undefined) node at the given key
-
has
Recursively determine whether this node has children with the given names. If any child along the path does not exist, returnfalse.- Parameters:
names- the child names- Returns:
trueif a call toget(String...)with the givennameswould succeed without needing to create any new nodes;falseotherwise
-
hasDefined
public boolean hasDefined(int index) Determine whether this node has a defined child with the given index. Property node types always contain exactly one value.- Parameters:
index- the index- Returns:
trueif there is a node at the given index and itstypeis notModelType.UNDEFINED
-
hasDefined
Determine whether this node has a defined child with the given name. Property node types always contain exactly one value with a key equal to the property name.- Parameters:
key- the name- Returns:
trueif there is a node at the given index and itstypeis notModelType.UNDEFINED
-
hasDefined
Recursively determine whether this node has defined children with the given names. If any child along the path does not exist or is not defined, returnfalse.- Parameters:
names- the child names- Returns:
trueif a call toget(String...)with the givennameswould succeed without needing to create any new nodes and without traversing any undefined nodes;falseotherwise
-
keys
Get the set of keys contained in this object. Property node types always contain exactly one value with a key equal to the property name. Other non-object types will throw an exception.- Returns:
- the key set
- Throws:
IllegalArgumentException- if this node'stypeis notModelType.OBJECTorModelType.PROPERTY
-
asList
Get the list of entries contained in this object. Property node types always contain exactly one entry (itself). Lists will return an unmodifiable view of their contained list. Objects will return a list of properties corresponding to the mappings within the object. OtherisDefined()types will return an empty list.- Returns:
- the entry list
- Throws:
IllegalArgumentException- if this node is notdefined
-
asList
- Parameters:
defVal- the default value to return if this node is not defined- Returns:
- the list value or an empty list
-
asListOrEmpty
- Returns:
- the list value or an empty list (not
null)
-
get
Recursively get the children of this node with the given names. If any child along the path does not exist, create it. If any node is the path is undefined, it will be initialized to be of typeModelType.OBJECT.- Parameters:
names- the child names- Returns:
- the child
- Throws:
IllegalArgumentException- if a node does not support getting a child with the given name path
-
toString
Get a human-readable string representation of this model node, formatted nicely (possibly on multiple lines). -
writeString
Output the DMR string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.- Parameters:
writer- A PrintWriter instance used to output the DMR string.compact- Flag that indicates whether or not the string should be all on one line (i.e.true) or should be printed on multiple lines (false).
-
toJSONString
Get a JSON string representation of this model node, formatted nicely, if requested.- Parameters:
compact- Flag that indicates whether or not the string should be all on one line (i.e.true) or should be printed on multiple lines (false).- Returns:
- The JSON string.
-
writeJSONString
Output the JSON string representation of this model node, formatted nicely, if requested to the supplied PrintWriter instance.- Parameters:
writer- A PrintWriter instance used to output the JSON string.compact- Flag that indicates whether or not the string should be all on one line (i.e.true) or should be printed on multiple lines (false).
-
fromString
Get a model node from a string representation of the model node.- Parameters:
input- the input string- Returns:
- the model node
-
fromJSONString
-
fromStream
Get a model node from a text representation of the model node. The stream must be decodable using the UTF-8 charset.- Parameters:
stream- the source stream- Returns:
- the model node
- Throws:
IOException
-
fromJSONStream
Get a model node from a JSON text representation of the model node. The stream should be encoded in UTF-8.- Parameters:
stream- the source stream- Returns:
- the model node
- Throws:
IOException
-
fromBase64
Reads base64 data from the passed stream, and deserializes the decoded result.- Returns:
- the decoded model node
- Throws:
IOException- if the passed stream has an issue- See Also:
-
fromBase64String
Reads base64 data from the passed string, and deserializes the decoded result.- Returns:
- the decoded model node
- Throws:
IOException- if the passed stream has an issue- See Also:
-
resolve
Return a copy of this model node, with all values of typeModelType.EXPRESSIONlocally resolved. The caller must have permission to access all of the system properties named in the node tree. If an expression begins with {@code ${env.} then a system property named {@code env.@lt;remainder of expression@gt;} will be checked, and if not present a {@link System#getenv(String) system environment variable named @lt;remainder of expression@gt;} will be checked. In that case the caller must have permission to access the environment variable. @return the resolved copy @throws IllegalStateException if there is a value of type {@link ModelType#EXPRESSION} in the node tree and there is no system property or environment variable that matches the expression @throws SecurityException if a security manager exists and its {@link SecurityManager#checkPermission checkPermission} method doesn't allow access to the relevant system property or environment variable -
equals
Determine whether this object is equal to another. -
equals
Determine whether this object is equal to another.- Parameters:
other- the other object- Returns:
trueif they are equal,falseotherwise
-
hashCode
public int hashCode()Get the hash code of this node object. Note that unless the value isprotect()ed, the hash code may change over time, thus making unprotected nodes unsuitable for use as hash table keys. -
clone
Clone this model node. -
getType
Get the current type of this node.- Returns:
- the node type
-
writeExternal
Write this node's content in binary format to the given target.- Specified by:
writeExternalin interfaceExternalizable- Parameters:
out- the target to which the content should be written- Throws:
IOException- if an I/O error occurs
-
writeExternal
Write this node's content in binary format to the given target.- Parameters:
out- the target to which the content should be written- Throws:
IOException- if an I/O error occurs
-
writeExternal
Write this node's content in binary format to the given target.- Parameters:
out- the target to which the content should be written- Throws:
IOException- if an I/O error occurs
-
writeExternal
Write this node's content in binary format to the given target.- Parameters:
out- the target to which the content should be written- Throws:
IOException- if an I/O error occurs
-
readExternal
Read this node's content in binary format from the given source.- Specified by:
readExternalin interfaceExternalizable- Parameters:
in- the source from which the content should be read- Throws:
IOException- if an I/O error occurs
-
readExternal
Read this node's content in binary format from the given source.- Parameters:
in- the source from which the content should be read- Throws:
IOException- if an I/O error occurs
-
readExternal
Read this node's content in binary format from the given source.- Parameters:
in- the source from which the content should be read- Throws:
IOException- if an I/O error occurs
-
readExternal
Read this node's content in binary format from the given source.- Parameters:
in- the source from which the content should be read- Throws:
IOException- if an I/O error occurs
-
writeBase64
Encodes the serialized representation in base64 form and writes it to the specified output stream.- Parameters:
stream- the stream to write to- Throws:
IOException- if the specified stream has an issue
-
add(ValueExpression)instead.