All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testifyproject.snakeyaml.nodes.MappingNode Maven / Gradle / Ivy

There is a newer version: 1.0.6
Show newest version
/**
 * Copyright (c) 2008, http://www.snakeyaml.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.testifyproject.snakeyaml.nodes;

import java.util.List;

import org.testifyproject.snakeyaml.error.Mark;

/**
 * Represents a map.
 * 

* A map is a collection of unsorted key-value pairs. *

*/ public class MappingNode extends CollectionNode { private List value; private boolean merged = false; public MappingNode(Tag tag, boolean resolved, List value, Mark startMark, Mark endMark, Boolean flowStyle) { super(tag, startMark, endMark, flowStyle); if (value == null) { throw new NullPointerException("value in a Node is required."); } this.value = value; this.resolved = resolved; } public MappingNode(Tag tag, List value, Boolean flowStyle) { this(tag, true, value, null, null, flowStyle); } @Override public NodeId getNodeId() { return NodeId.mapping; } /** * Returns the entries of this map. * * @return List of entries. */ public List getValue() { return value; } public void setValue(List merge) { value = merge; } public void setOnlyKeyType(Class keyType) { for (NodeTuple nodes : value) { nodes.getKeyNode().setType(keyType); } } public void setTypes(Class keyType, Class valueType) { for (NodeTuple nodes : value) { nodes.getValueNode().setType(valueType); nodes.getKeyNode().setType(keyType); } } @Override public String toString() { String values; StringBuilder buf = new StringBuilder(); for (NodeTuple node : getValue()) { buf.append("{ key="); buf.append(node.getKeyNode()); buf.append("; value="); if (node.getValueNode() instanceof CollectionNode) { // to avoid overflow in case of recursive structures buf.append(System.identityHashCode(node.getValueNode())); } else { buf.append(node.toString()); } buf.append(" }"); } values = buf.toString(); return "<" + this.getClass().getName() + " (tag=" + getTag() + ", values=" + values + ")>"; } /** * @param merged * - true if map contains merge node */ public void setMerged(boolean merged) { this.merged = merged; } /** * @return true if map contains merge node */ public boolean isMerged() { return merged; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy