public final class ArrayValue extends ValueNode<ArrayValue> implements ValueNodeContainer, Iterable<ValueNode<?>>
getType()
method will return a FieldType matching all elements or FieldType.UNDEFINED if elements contain
different types. If ArrayValue has no elements, its defaultType will be returned.SingleValue,
Record,
Node,
Field,
FieldType,
Serialized FormNode.DuplicateNodeAction, Node.NodeTypeSession.SessionImpl| Constructor and Description |
|---|
ArrayValue()
Creates a new empty array with an
FieldType.UNDEFINED default type. |
ArrayValue(FieldType defaultType)
Creates a new empty array.
|
ArrayValue(Object... collection)
Creates a new array populated with the given objects.
|
| Modifier and Type | Method and Description |
|---|---|
ArrayValue |
addAll(ArrayValue array)
Appends cloned copies of all elements from the specified array to this array.
|
ArrayValue |
addAll(Collection<?> collection)
Adds all elements from the specified collection to this array.
|
ArrayValue |
addNull(FieldType type)
Adds a typed
null value to this container. |
ArrayValue |
addNull(int index,
FieldType type)
Inserts a typed
null value at the given index. |
ArrayValue |
addValue(FieldType type,
Object element)
Adds a value with the specified
FieldType to this container. |
ArrayValue |
addValue(int index,
FieldType type,
Object element)
Inserts a value with the specified
FieldType at the given index, shifting subsequent elements to the right. |
ArrayValue |
addValue(int index,
Object element)
Inserts a value at the given index, inferring the
FieldType from the value's class. |
ArrayValue |
addValue(Object element)
Adds a value to this container, inferring the
FieldType from the value's class. |
ArrayValue |
clone()
Returns a deep copy of this array, cloning every element.
|
int |
compareTo(ValueNode<ArrayValue> o)
Compares this array to another by length first, then element-by-element.
|
int |
count(Predicate<ValueNode<?>> predicate)
Returns the number of elements in this array that match the given predicate.
|
ArrayValue |
ensureCapacity(int minCapacity)
Increases the capacity of this array's internal list, if necessary, to ensure it can hold at least
the specified number of elements without reallocating.
|
boolean |
equals(Object o)
Indicates whether the given object is an
ArrayValue with equal elements. |
ArrayValue |
findAll(Predicate<ValueNode<?>> predicate)
Returns a new ArrayValue containing all elements that match the given predicate.
|
int |
findFirst(Predicate<ValueNode<?>> predicate,
int fromIndex)
Returns the index of the first element in this array that matches the given predicate,
starting at the specified index, or -1 if no element matches.
|
int |
findLast(Predicate<ValueNode<?>> predicate,
int fromIndex)
Returns the index of the last element in this array that matches the given predicate,
searching backward from the specified index, or -1 if no element matches.
|
void |
forEach(Consumer<? super ValueNode<?>> consumer)
Performs the given action for each element in this array.
|
void |
forEachArrayValue(Consumer<ArrayValue> action)
Performs the given action for each ArrayValue element in this array.
|
void |
forEachRecord(Consumer<Record> action)
Performs the given action for each Record element in this array.
|
void |
forEachSingleValue(Consumer<SingleValue> action)
Performs the given action for each SingleValue element in this array.
|
protected static ArrayValue |
fromArray(Object array) |
FieldType |
getDefaultType()
Returns the default
FieldType used when this array is empty. |
int |
getNodeDepth()
Returns this node's distance from its root node.
|
Node.NodeType |
getNodeType()
Returns the concrete
Node.NodeType of this node. |
long |
getSizeInBytes()
Returns the estimated size of this value node in bytes, including object overhead.
|
FieldType |
getType()
Returns
defaultType if there are no elements, the FieldType matching all elements if they are the same
or FieldType.UNDEFINED if elements contain multiple types. |
ArrayValue |
getValue()
Returns the underlying value held by this node.
|
Object |
getValue(int index)
Returns the value at the specified index (for zero or positive indexes) or from the end of the list (for negative indexes by adding index to the size of the list).
|
ArrayValue |
getValueAsArray(int index)
Returns the element at the specified index cast to an
ArrayValue. |
BigDecimal |
getValueAsBigDecimal(int index)
Returns the element at the specified index as a
BigDecimal. |
BigInteger |
getValueAsBigInteger(int index)
Returns the element at the specified index as a
BigInteger. |
boolean |
getValueAsBoolean(int index)
Returns the element at the specified index as a
boolean. |
byte |
getValueAsByte(int index)
Returns the element at the specified index as a
byte. |
byte[] |
getValueAsBytes(int index)
Returns the element at the specified index as a
byte[]. |
char |
getValueAsChar(int index)
Returns the element at the specified index as a
char. |
Date |
getValueAsDate(int index)
Returns the element at the specified index as a
Date. |
Date |
getValueAsDatetime(int index)
Returns the element at the specified index as a
Date (datetime). |
double |
getValueAsDouble(int index)
Returns the element at the specified index as a
double. |
float |
getValueAsFloat(int index)
Returns the element at the specified index as a
float. |
Instant |
getValueAsInstant(int index)
Returns the element at the specified index as an
Instant. |
int |
getValueAsInteger(int index)
Returns the element at the specified index as an
int. |
<T> List<T> |
getValueAsList(int index,
Class<T> elementType)
Returns the array element value at the specified index as a
List with each element coerced to the specified type. |
LocalDate |
getValueAsLocalDate(int index)
Returns the element at the specified index as a
LocalDate. |
LocalDateTime |
getValueAsLocalDateTime(int index)
Returns the element at the specified index as a
LocalDateTime. |
LocalTime |
getValueAsLocalTime(int index)
Returns the element at the specified index as a
LocalTime. |
long |
getValueAsLong(int index)
Returns the element at the specified index as a
long. |
Record |
getValueAsRecord(int index)
Returns the element at the specified index cast to a
Record. |
short |
getValueAsShort(int index)
Returns the element at the specified index as a
short. |
SingleValue |
getValueAsSingleValue(int index)
Returns the element at the specified index cast to a
SingleValue. |
String |
getValueAsString()
Returns a string representation of the value held by this node.
|
String |
getValueAsString(int index)
Returns the string representation of the element at the specified index.
|
Time |
getValueAsTime(int index)
Returns the element at the specified index as a
Time. |
UUID |
getValueAsUuid(int index)
Returns the element at the specified index as a
UUID. |
ValueNode<?> |
getValueNode(int index)
Returns the value node at the specified index (for zero or positive indexes) or from the end of the list (for negative indexes by adding index to the size of the list).
|
List<Object> |
getValues()
Returns a list of values.
|
<T> List<T> |
getValues(Class<T> elementType)
Returns a list of values with each element coerced to the supplied type.
|
Stream<Object> |
getValueStream()
Returns a stream of values.
|
<T> Stream<T> |
getValueStream(Class<T> elementType)
Returns a stream of values with each element coerced to the supplied type.
|
boolean |
hasChildNodes()
Returns
true if this node contains any sub nodes. |
boolean |
hasChildRecords()
Returns
true if this node contains any descendant, record nodes. |
int |
hashCode()
Returns a hash code based on the internal element list.
|
boolean |
hasValue()
Returns
true if this container has had any value added, including null. |
int |
indexOfNode(Node child)
Returns the index of the specified node in this array using identity comparison, or
-1 if not found. |
int |
indexOfValue(Object value)
Returns the index of the first element whose underlying value equals the specified value, or
-1 if not found. |
boolean |
isArray()
Returns
true if this value node is an ArrayValue. |
boolean |
isEmpty()
Returns
true if this array contains no elements -- equivalent to size() == 0. |
boolean |
isNotEmpty()
Returns
true if this array contains elements -- equivalent to size() > 0. |
Iterator<ValueNode<?>> |
iterator() |
Stream<ValueNode<?>> |
parallelStream()
Returns a parallel Stream of the elements in this array.
|
protected void |
removeChildNode(Node child) |
Object |
removeValue(int index)
Removes and returns the underlying value of the element at the specified index.
|
boolean |
removeValue(Object value)
Removes all elements whose underlying value equals the specified value.
|
ArrayValue |
setDefaultType(FieldType defaultType)
Sets the default
FieldType used when this array is empty. |
ArrayValue |
setNull(int index,
FieldType type)
Replaces the element at the specified index with a typed
null value. |
ArrayValue |
setValue(int index,
FieldType type,
Object element)
Replaces the element at the specified index with a new value of the given type.
|
ArrayValue |
setValue(int index,
Object element)
Replaces the element at the specified index with a new value, inferring the
FieldType. |
int |
size()
Returns the number of elements in this array.
|
ArrayValue |
sort()
Sorts this array using the default
ValueNodeComparator. |
ArrayValue |
sort(Comparator<ValueNode<?>> comparator)
Sorts this array using the specified comparator.
|
Stream<ValueNode<?>> |
stream()
Returns a sequential Stream of the elements in this array.
|
byte[] |
toBinary()
Serializes this array to a binary byte array.
|
String |
toJson()
Serializes this array to a JSON string.
|
String |
toString()
Returns a string representation of this array in the form
[element1, element2, ...]. |
String |
toXml()
Serializes this array to an XML string.
|
asArray, asArrayValue, asRecord, asSingleValue, from, from, getParentNode, isNotArray, isNotNull, isNotRecord, isNotSingleValue, isNull, isRecord, isSingleValue, isValueNode, nullValue, nullValue, setParentNodeassertNotAncestorOf, containsSessionProperty, containsSessionProperty, containsSessionProperty, copySessionPropertiesFrom, getParentField, getParentRecord, getSessionProperty, getSessionProperty, getSessionProperty, isAncestorOf, isChildNode, keySet, removeSessionProperties, setSessionProperty, setSessionProperty, setSessionPropertyfinalize, getClass, notify, notifyAll, wait, wait, waitspliteratorpublic ArrayValue()
FieldType.UNDEFINED default type.public ArrayValue(FieldType defaultType)
defaultType - the value returned by getType() if there are no elements.public ArrayValue(Object... collection)
ValueNode instances are added directly;
Iterable instances have their elements added individually; all other objects are wrapped via
ValueNode.from(Object).collection - the objects to add, may be nullpublic ArrayValue ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacityArrayValue for method chainingpublic ArrayValue addValue(FieldType type, Object element)
FieldType to this container.addValue in interface ValueNodeContainertype - the field type of the value to add, or null to infer the typeelement - the value to add, may be nullpublic ArrayValue addValue(Object element)
FieldType from the value's class.addValue in interface ValueNodeContainerelement - the value to add, may be nullpublic ArrayValue addAll(ArrayValue array)
array - the source array whose elements are to be addedArrayValue for method chainingpublic ArrayValue addAll(Collection<?> collection)
collection - the collection of elements to add, may be nullpublic ArrayValue addValue(int index, FieldType type, Object element)
FieldType at the given index, shifting subsequent elements to the right.index - the position at which to insert the valuetype - the field type of the value, or null to infer the typeelement - the value to insert, may be nullArrayValue for method chainingpublic ArrayValue addValue(int index, Object element)
FieldType from the value's class.index - the position at which to insert the valueelement - the value to insert, may be nullArrayValue for method chainingpublic ArrayValue setValue(int index, FieldType type, Object element)
type and element are null, the type of the existing element is preserved.index - the position of the element to replacetype - the field type of the new value, or null to inferelement - the new value, may be nullArrayValue for method chainingpublic ArrayValue setValue(int index, Object element)
FieldType.index - the position of the element to replaceelement - the new value, may be nullArrayValue for method chainingpublic ArrayValue addNull(FieldType type)
null value to this container.addNull in interface ValueNodeContainertype - the field type of the null value to addpublic ArrayValue addNull(int index, FieldType type)
null value at the given index.index - the position at which to inserttype - the field type for the null valueArrayValue for method chainingpublic ArrayValue setNull(int index, FieldType type)
null value.index - the position of the element to replacetype - the field type for the null valueArrayValue for method chainingpublic Object removeValue(int index)
index - the index of the element to removeIndexOutOfBoundsException - if the index is out of rangepublic boolean removeValue(Object value)
value - the value to match for removaltrue if at least one element was removedpublic FieldType getDefaultType()
FieldType used when this array is empty.nullpublic ArrayValue setDefaultType(FieldType defaultType)
FieldType used when this array is empty. A null value
is normalized to FieldType.UNDEFINED.defaultType - the default field typeArrayValue for method chainingpublic FieldType getType()
defaultType if there are no elements, the FieldType matching all elements if they are the same
or FieldType.UNDEFINED if elements contain multiple types.getType in class ValueNode<ArrayValue>nullpublic Node.NodeType getNodeType()
Node.NodeType of this node.getNodeType in class NodeNodeType#ARRAYpublic boolean hasChildNodes()
true if this node contains any sub nodes.
Returns true if this array contains at least one element.
hasChildNodes in class Nodepublic boolean hasChildRecords()
true if this node contains any descendant, record nodes.
Returns true if any element in this array is a Record or itself contains child records.
hasChildRecords in class Nodeprotected void removeChildNode(Node child)
removeChildNode in class Nodepublic int indexOfNode(Node child)
-1 if not found.child - the node to search for-1public int indexOfValue(Object value)
-1 if not found.value - the value to search for-1public int getNodeDepth()
Adjusts the depth by subtracting one since arrays are logically transparent in the record hierarchy.
getNodeDepth in class Nodepublic boolean isArray()
isArray in class ValueNode<ArrayValue>true if this is an array, false otherwiseValueNode.asArrayValue()public int size()
public boolean isEmpty()
true if this array contains no elements -- equivalent to size() == 0.public boolean isNotEmpty()
true if this array contains elements -- equivalent to size() > 0.public boolean hasValue()
true if this container has had any value added, including null.
Otherwise, it returns false.
Returns true if this array is not empty.
hasValue in interface ValueNodeContainerpublic Object getValue(int index)
public <T> List<T> getValues(Class<T> elementType)
public <T> Stream<T> getValueStream(Class<T> elementType)
public ValueNode<?> getValueNode(int index)
public void forEach(Consumer<? super ValueNode<?>> consumer)
public void forEachRecord(Consumer<Record> action)
action - the action to perform on each Record elementpublic void forEachArrayValue(Consumer<ArrayValue> action)
action - the action to perform on each ArrayValue elementpublic void forEachSingleValue(Consumer<SingleValue> action)
action - the action to perform on each SingleValue elementpublic Stream<ValueNode<?>> stream()
public Stream<ValueNode<?>> parallelStream()
public int findFirst(Predicate<ValueNode<?>> predicate, int fromIndex)
predicate - the predicate to test elements againstfromIndex - the index to start searching from (negative values are treated as 0)public int findLast(Predicate<ValueNode<?>> predicate, int fromIndex)
predicate - the predicate to test elements againstfromIndex - the index to start searching backward from (-1 or values >= size start from the end)public ArrayValue findAll(Predicate<ValueNode<?>> predicate)
predicate - the predicate to test elements againstpublic int count(Predicate<ValueNode<?>> predicate)
predicate - the predicate to test elements againstpublic ArrayValue getValueAsArray(int index)
ArrayValue.index - the index of the elementArrayValueClassCastException - if the element is not an ArrayValuepublic Record getValueAsRecord(int index)
Record.index - the index of the elementRecordClassCastException - if the element is not a Recordpublic SingleValue getValueAsSingleValue(int index)
SingleValue.index - the index of the elementSingleValueClassCastException - if the element is not a SingleValuepublic String getValueAsString(int index)
index - the index of the elementpublic Date getValueAsDatetime(int index)
Date (datetime).index - the index of the elementpublic Date getValueAsDate(int index)
Date.index - the index of the elementpublic Time getValueAsTime(int index)
Time.index - the index of the elementpublic int getValueAsInteger(int index)
int.index - the index of the elementpublic long getValueAsLong(int index)
long.index - the index of the elementpublic short getValueAsShort(int index)
short.index - the index of the elementpublic byte getValueAsByte(int index)
byte.index - the index of the elementpublic boolean getValueAsBoolean(int index)
boolean.index - the index of the elementpublic char getValueAsChar(int index)
char.index - the index of the elementpublic double getValueAsDouble(int index)
double.index - the index of the elementpublic float getValueAsFloat(int index)
float.index - the index of the elementpublic byte[] getValueAsBytes(int index)
byte[].index - the index of the elementpublic BigDecimal getValueAsBigDecimal(int index)
BigDecimal.index - the index of the elementpublic BigInteger getValueAsBigInteger(int index)
BigInteger.index - the index of the elementpublic Instant getValueAsInstant(int index)
Instant.index - the index of the elementpublic LocalDateTime getValueAsLocalDateTime(int index)
LocalDateTime.index - the index of the elementpublic LocalDate getValueAsLocalDate(int index)
LocalDate.index - the index of the elementpublic LocalTime getValueAsLocalTime(int index)
LocalTime.index - the index of the elementpublic UUID getValueAsUuid(int index)
UUID.index - the index of the elementpublic ArrayValue getValue()
SingleValue, this is the wrapped object.
For ArrayValue, this returns the array itself. For Record, this returns the record itself.
Returns this ArrayValue instance (arrays are self-referencing values).
getValue in class ValueNode<ArrayValue>null if this node holds a null valuepublic String getValueAsString()
getValueAsString in class ValueNode<ArrayValue>"null" if the value is nullpublic long getSizeInBytes()
getSizeInBytes in class ValueNode<ArrayValue>public ArrayValue sort()
ValueNodeComparator.
The sort is performed in-place, modifying this array.ValueNodeComparator.DEFAULTpublic ArrayValue sort(Comparator<ValueNode<?>> comparator)
comparator - the comparator to use for sortingpublic int compareTo(ValueNode<ArrayValue> o)
compareTo in interface Comparable<ValueNode<ArrayValue>>o - the other value node to compare topublic boolean equals(Object o)
ArrayValue with equal elements.public int hashCode()
public ArrayValue clone()
clone in class ValueNode<ArrayValue>ArrayValue with cloned elements and the same default typepublic String toString()
[element1, element2, ...].public String toJson()
toJson in class ValueNode<ArrayValue>Record.toJson(ValueNode)public String toXml()
toXml in class ValueNode<ArrayValue>Record.toXml(ValueNode)public byte[] toBinary()
Record.toBinary(ValueNode)protected static ArrayValue fromArray(Object array)
Copyright (c) 2006-2026 North Concepts Inc. All Rights Reserved.