
org.snakeyaml.engine.v2.nodes.MappingNode Maven / Gradle / Ivy
Show all versions of snakeyaml-engine Show documentation
/**
* Copyright (c) 2018, 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.snakeyaml.engine.v2.nodes;
import org.snakeyaml.engine.v2.common.FlowStyle;
import org.snakeyaml.engine.v2.exceptions.Mark;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* 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, FlowStyle flowStyle, Optional startMark, Optional endMark) {
super(tag, flowStyle, startMark, endMark);
Objects.requireNonNull("value in a Node is required.");
this.value = value;
this.resolved = resolved;
}
public MappingNode(Tag tag, List value, FlowStyle flowStyle) {
this(tag, true, value, flowStyle, Optional.empty(), Optional.empty());
}
@Override
public NodeType getNodeType() {
return NodeType.MAPPING;
}
/**
* Returns the entries of this map.
*
* @return List of entries.
*/
public List getValue() {
return value;
}
public void setValue(List mergedValue) {
value = mergedValue;
}
@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;
}
}