View Javadoc

    1   /**
    2    * Copyright (c) 2008-2011, http://www.snakeyaml.org
    3    *
    4    * Licensed under the Apache License, Version 2.0 (the "License");
    5    * you may not use this file except in compliance with the License.
    6    * You may obtain a copy of the License at
    7    *
    8    *     http://www.apache.org/licenses/LICENSE-2.0
    9    *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16
    17  package org.yaml.snakeyaml.nodes;
    18
    19  import java.util.List;
    20
    21  import org.yaml.snakeyaml.error.Mark;
    22
    23  /**
    24   * Represents a sequence.
    25   * <p>
    26   * A sequence is a ordered collection of nodes.
    27   * </p>
    28   */
    29  public class SequenceNode extends CollectionNode {
    30      final private List<Node> value;
    31
    32      public SequenceNode(Tag tag, boolean resolved, List<Node> value, Mark startMark, Mark endMark,
    33              Boolean flowStyle) {
    34          super(tag, startMark, endMark, flowStyle);
    35          if (value == null) {
    36              throw new NullPointerException("value in a Node is required.");
    37          }
    38          this.value = value;
    39          this.resolved = resolved;
    40      }
    41
    42      public SequenceNode(Tag tag, List<Node> value, Boolean flowStyle) {
    43          this(tag, true, value, null, null, flowStyle);
    44      }
    45
    46      @Override
    47      public NodeId getNodeId() {
    48          return NodeId.sequence;
    49      }
    50
    51      /**
    52       * Returns the elements in this sequence.
    53       *
    54       * @return Nodes in the specified order.
    55       */
    56      public List<Node> getValue() {
    57          return value;
    58      }
    59
    60      public void setListType(Class<? extends Object> listType) {
    61          for (Node node : value) {
    62              node.setType(listType);
    63          }
    64      }
    65
    66      public String toString() {
    67          return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue()
    68                  + ")>";
    69      }
    70  }