ArrayNode extends Node implements Iterable<Node> { public ArrayNode withValue(Node node) { ArrayList<Node> newElements = new ArrayList<>(elements); newElements.add(Objects.requireNonNull(node)); return new ArrayNode(newElements, getSourceLocation(), false); } ArrayNode(List<Node> elements, SourceLocation sourceLocation);   ArrayNode(List<Node> elements, SourceLocation sourceLocation, boolean defensiveCopy); @Override Iterator<Node> iterator(); @Override NodeType getType(); @Override R accept(NodeVisitor<R> visitor); @Override ArrayNode expectArrayNode(String errorMessage); @Override Optional<ArrayNode> asArrayNode(); List<Node> getElements(); Optional<Node> get(int index); boolean isEmpty(); int size(); ArrayNode withValue(Node node); List<T> getElementsAs(Class<T> type); @SuppressWarnings("unchecked") List<T> getElementsAs(Function<K, T> f); ArrayNode merge(ArrayNode other); static Collector<T, List<Node>, ArrayNode> collect(); static Collector<T, List<Node>, ArrayNode> collect(SourceLocation sloc); @Override boolean equals(Object other); @Override int hashCode();  }
@Test public void withValue() { StringNode strNode1 = Node.from("abc"); StringNode strNode2 = Node.from("abc"); ArrayNode node = Node.arrayNode() .withValue(strNode1) .withValue(strNode2); assertThat(node.size(), is(2)); assertSame(strNode1, node.get(0).get()); assertSame(strNode2, node.get(1).get()); }