• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2008, SnakeYAML
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.yaml.snakeyaml.nodes;
15 
16 import java.util.List;
17 import org.yaml.snakeyaml.DumperOptions;
18 import org.yaml.snakeyaml.error.Mark;
19 
20 /**
21  * Represents a sequence.
22  * <p>
23  * A sequence is a ordered collection of nodes.
24  * </p>
25  */
26 public class SequenceNode extends CollectionNode<Node> {
27 
28   private final List<Node> value;
29 
SequenceNode(Tag tag, boolean resolved, List<Node> value, Mark startMark, Mark endMark, DumperOptions.FlowStyle flowStyle)30   public SequenceNode(Tag tag, boolean resolved, List<Node> value, Mark startMark, Mark endMark,
31       DumperOptions.FlowStyle flowStyle) {
32     super(tag, startMark, endMark, flowStyle);
33     if (value == null) {
34       throw new NullPointerException("value in a Node is required.");
35     }
36     this.value = value;
37     this.resolved = resolved;
38   }
39 
SequenceNode(Tag tag, List<Node> value, DumperOptions.FlowStyle flowStyle)40   public SequenceNode(Tag tag, List<Node> value, DumperOptions.FlowStyle flowStyle) {
41     this(tag, true, value, null, null, flowStyle);
42   }
43 
44   /*
45    * Existed in older versions but replaced with {@link DumperOptions.SequenceStyle}-based
46    * constructor. Restored in v1.22 for backwards compatibility.
47    *
48    * @deprecated Since restored in v1.22. Use {@link SequenceNode#SequenceNode(Tag, List<Node>,
49    * org.yaml.snakeyaml.DumperOptions.FlowStyle) }.
50    */
51   @Deprecated
SequenceNode(Tag tag, List<Node> value, Boolean style)52   public SequenceNode(Tag tag, List<Node> value, Boolean style) {
53     this(tag, value, DumperOptions.FlowStyle.fromBoolean(style));
54   }
55 
56   /*
57    * Existed in older versions but replaced with {@link DumperOptions.SequenceStyle}-based
58    * constructor. Restored in v1.22 for backwards compatibility.
59    *
60    * @deprecated Since restored in v1.22. Use {@link SequenceNode#SequenceNode(Tag, boolean,
61    * List<Node>, Mark, Mark, org.yaml.snakeyaml.DumperOptions.FlowStyle) }.
62    */
63   @Deprecated
SequenceNode(Tag tag, boolean resolved, List<Node> value, Mark startMark, Mark endMark, Boolean style)64   public SequenceNode(Tag tag, boolean resolved, List<Node> value, Mark startMark, Mark endMark,
65       Boolean style) {
66     this(tag, resolved, value, startMark, endMark, DumperOptions.FlowStyle.fromBoolean(style));
67   }
68 
69   @Override
getNodeId()70   public NodeId getNodeId() {
71     return NodeId.sequence;
72   }
73 
74   /**
75    * Returns the elements in this sequence.
76    *
77    * @return Nodes in the specified order.
78    */
getValue()79   public List<Node> getValue() {
80     return value;
81   }
82 
setListType(Class<? extends Object> listType)83   public void setListType(Class<? extends Object> listType) {
84     for (Node node : value) {
85       node.setType(listType);
86     }
87   }
88 
toString()89   public String toString() {
90     return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() + ")>";
91   }
92 }
93