public final class ArrayNode extends Node implements java.lang.Iterable<Node>, ToSmithyBuilder<ArrayNode>
Modifier and Type | Class and Description |
---|---|
static class |
ArrayNode.Builder
Builder used to efficiently create an ArrayNode.
|
Node.NonNumericFloat
Constructor and Description |
---|
ArrayNode(java.util.List<Node> elements,
SourceLocation sourceLocation) |
Modifier and Type | Method and Description |
---|---|
<R> R |
accept(NodeVisitor<R> visitor)
Accepts a visitor with the node.
|
java.util.Optional<ArrayNode> |
asArrayNode()
Gets the node as an ArrayNode if it is an array.
|
static ArrayNode.Builder |
builder() |
static <T extends ToNode> |
collect() |
static <T extends ToNode> |
collect(SourceLocation sloc) |
boolean |
equals(java.lang.Object other) |
ArrayNode |
expectArrayNode(java.lang.String errorMessage)
Casts the current node to an
ArrayNode , throwing
ExpectationNotMetException when the node is the wrong type. |
ArrayNode |
expectArrayNode(java.util.function.Supplier<java.lang.String> errorMessage)
Casts the current node to an
ArrayNode , throwing
ExpectationNotMetException when the node is the wrong type. |
java.util.Optional<Node> |
get(int index)
Gets a node from the given index.
|
java.util.List<Node> |
getElements()
Gets the list of nodes.
|
<T extends Node> |
getElementsAs(java.lang.Class<T> type)
Gets the elements of the array as a list of a specific type of
Node . |
<T,K extends Node> |
getElementsAs(java.util.function.Function<K,T> f)
Gets the elements of the ArrayNode as a specific type by applying
a mapping function to each node.
|
NodeType |
getType()
Gets the type of the node.
|
int |
hashCode() |
boolean |
isEmpty()
Returns true if the array node is empty.
|
java.util.Iterator<Node> |
iterator() |
ArrayNode |
merge(ArrayNode other)
Merges two ArrayNodes into a new ArrayNode.
|
int |
size()
Returns the number of elements in the array node.
|
SmithyBuilder<ArrayNode> |
toBuilder()
Take this object and create a builder that contains all of the
current property values of this object.
|
ArrayNode |
withValue(Node node)
Copies the values from the current array node, adding the given node,
returning them in a new
ArrayNode . |
arrayNode, arrayNode, asBooleanNode, asNullNode, asNumberNode, asObjectNode, assertEquals, asStringNode, diff, expectArrayNode, expectBooleanNode, expectBooleanNode, expectBooleanNode, expectNullNode, expectNullNode, expectNullNode, expectNumberNode, expectNumberNode, expectNumberNode, expectObjectNode, expectObjectNode, expectObjectNode, expectStringNode, expectStringNode, expectStringNode, from, from, from, fromNodes, fromNodes, fromStrings, fromStrings, getSourceLocation, isArrayNode, isBooleanNode, isNullNode, isNumberNode, isObjectNode, isStringNode, loadArrayOfString, nullNode, objectNode, objectNode, objectNodeBuilder, parse, parse, parse, parse, parseJsonWithComments, parseJsonWithComments, prettyPrintJson, prettyPrintJson, printJson, toNode, withDeepSortedKeys, withDeepSortedKeys
public ArrayNode(java.util.List<Node> elements, SourceLocation sourceLocation)
public static ArrayNode.Builder builder()
public SmithyBuilder<ArrayNode> toBuilder()
ToSmithyBuilder
toBuilder
in interface ToSmithyBuilder<ArrayNode>
public java.util.Iterator<Node> iterator()
iterator
in interface java.lang.Iterable<Node>
public <R> R accept(NodeVisitor<R> visitor)
Node
public ArrayNode expectArrayNode(java.lang.String errorMessage)
Node
ArrayNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectArrayNode
in class Node
errorMessage
- Error message to use if the node is of the wrong type.public ArrayNode expectArrayNode(java.util.function.Supplier<java.lang.String> errorMessage)
Node
ArrayNode
, throwing
ExpectationNotMetException
when the node is the wrong type.expectArrayNode
in class Node
errorMessage
- Error message supplier.public java.util.Optional<ArrayNode> asArrayNode()
Node
asArrayNode
in class Node
public java.util.List<Node> getElements()
public java.util.Optional<Node> get(int index)
index
- Index of the value to get.public boolean isEmpty()
public int size()
public ArrayNode withValue(Node node)
ArrayNode
.node
- The node to add.public <T extends Node> java.util.List<T> getElementsAs(java.lang.Class<T> type)
Node
.T
- Type of Node to expect in each position.type
- Type of Node to expect in each position.ExpectationNotMetException
- if the list contains elements of a different type.public <T,K extends Node> java.util.List<T> getElementsAs(java.util.function.Function<K,T> f)
Each Node is cast to K
and then mapped with the provided
function to return type T
.
ArrayNode array = Node.fromStrings("foo", "baz", "bar");
List<String> strings = array.getElementsAs(StringNode::getValue);
K
- Expected Node type.T
- Mapping function return value.f
- Mapping function that takes K
and return T
.ExpectationNotMetException
- if the list contains elements of a different type than K
.public ArrayNode merge(ArrayNode other)
If the current node has a source location, it is applied to the
result. Otherwise, the source location of other
is applied
to the result.
other
- Node to merge with.public static <T extends ToNode> java.util.stream.Collector<T,java.util.List<Node>,ArrayNode> collect()
T
- Type of value in the collection.public static <T extends ToNode> java.util.stream.Collector<T,java.util.List<Node>,ArrayNode> collect(SourceLocation sloc)
T
- Type of value in the collection.sloc
- Source location to use on the created node.public boolean equals(java.lang.Object other)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object