Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.MappingNode


        }
    }

    private void build(org.yaml.snakeyaml.nodes.Node yaml, Node parent) {
        if (yaml instanceof MappingNode) {
            final MappingNode mappingNode = (MappingNode) yaml;
            debug("writing map with size: {}", mappingNode.getValue().size());
            for (NodeTuple tuple : mappingNode.getValue()) {
                Node node = new Node();
                if (tuple.getKeyNode() instanceof ScalarNode) {
                    ScalarNode scalarNode = (ScalarNode) tuple.getKeyNode();
                    String keyValue = scalarNode.getValue();
                    debug("keyValue: {}", keyValue);
View Full Code Here


        SequenceNode seq = (SequenceNode) valueNode;
        if (seq.getValue().isEmpty()) { return null; // skip empty lists
        }
      }
      if (Tag.MAP.equals(valueNode.getTag())) {
        MappingNode seq = (MappingNode) valueNode;
        if (seq.getValue().isEmpty()) { return null; // skip empty maps
        }
      }
    }
    return tuple;
  }
View Full Code Here

    }

    protected Node representMapping(Tag tag, Map<? extends Object, Object> mapping,
            Boolean flowStyle) {
        List<NodeTuple> value = new ArrayList<NodeTuple>(mapping.size());
        MappingNode node = new MappingNode(tag, value, flowStyle);
        representedObjects.put(objectToRepresent, node);
        boolean bestStyle = true;
        for (Map.Entry<? extends Object, Object> entry : mapping.entrySet()) {
            Node nodeKey = representData(entry.getKey());
            Node nodeValue = representData(entry.getValue());
            if (!((nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null))) {
                bestStyle = false;
            }
            if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) {
                bestStyle = false;
            }
            value.add(new NodeTuple(nodeKey, nodeValue));
        }
        if (flowStyle == null) {
            if (defaultFlowStyle != FlowStyle.AUTO) {
                node.setFlowStyle(defaultFlowStyle.getStyleBoolean());
            } else {
                node.setFlowStyle(bestStyle);
            }
        }
        return node;
    }
View Full Code Here

                for (Node child1 : seq1.getValue()) {
                    Node child2 = iter2.next();
                    compareNodes(child1, child2);
                }
            } else {
                MappingNode seq1 = (MappingNode) node1;
                MappingNode seq2 = (MappingNode) node2;
                assertEquals(seq1.getTag(), seq2.getTag());
                assertEquals(seq1.getValue().size(), seq2.getValue().size());
                Iterator<NodeTuple> iter2 = seq2.getValue().iterator();
                for (NodeTuple child1 : seq1.getValue()) {
                    NodeTuple child2 = iter2.next();
                    compareNodes(child1.getKeyNode(), child2.getKeyNode());
                    compareNodes(child1.getValueNode(), child2.getValueNode());
                }
View Full Code Here

public class LoaderTest extends TestCase {

    public void testCompose1() {
        Yaml loader = new Yaml();
        String yaml = "abc: 3";
        MappingNode node = (MappingNode) loader.compose(new StringReader(yaml));
        List<NodeTuple> nodes = node.getValue();
        assertEquals(1, nodes.size());
        NodeTuple pairs = nodes.get(0);
        ScalarNode key = (ScalarNode) pairs.getKeyNode();
        assertEquals(Tag.STR, key.getTag());
        assertEquals("abc", key.getValue());
        //
        ScalarNode value = (ScalarNode) pairs.getValueNode();
        assertEquals(Tag.INT, value.getTag());
        assertEquals("3", value.getValue());
        //
        assertEquals(
                "<org.yaml.snakeyaml.nodes.MappingNode (tag=tag:yaml.org,2002:map, values={ key=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:str, value=abc)>; value=<NodeTuple keyNode=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:str, value=abc)>; valueNode=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:int, value=3)>> })>",
                node.toString());
    }
View Full Code Here

                    if (seq.getValue().isEmpty()) {
                        return null;// skip empty lists
                    }
                }
                if (Tag.MAP.equals(valueNode.getTag())) {
                    MappingNode seq = (MappingNode) valueNode;
                    if (seq.getValue().isEmpty()) {
                        return null;// skip empty maps
                    }
                }
            }
            return tuple;
View Full Code Here

        private class ConstructCar extends AbstractConstruct {

            @SuppressWarnings("unchecked")
            public Car construct(Node node) {
                Car car = new Car();
                MappingNode mapping = (MappingNode) node;
                List<NodeTuple> list = mapping.getValue();
                for (NodeTuple tuple : list) {
                    String field = toScalarString(tuple.getKeyNode());
                    if ("plate".equals(field)) {
                        car.setPlate(toScalarString(tuple.getValueNode()));
                    }
View Full Code Here

    }

    private class MyRepresenter extends Representer {
        @Override
        protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
            MappingNode node = super.representJavaBean(properties, javaBean);
            if (javaBean instanceof JavaBeanWithStaticState) {
                List<NodeTuple> value = node.getValue();
                value.add(new NodeTuple(representData("color"),
                        representData(JavaBeanWithStaticState.color)));
                value.add(new NodeTuple(representData("type"),
                        representData(JavaBeanWithStaticState.getType())));
            }
View Full Code Here

    }

    private class MyConstructor extends Constructor {
        protected Object constructObject(Node node) {
            if (node.getType().isAssignableFrom(JavaBeanWithStaticState.class)) {
                MappingNode beanNode = (MappingNode) node;
                List<NodeTuple> value = beanNode.getValue();
                List<NodeTuple> removed = new ArrayList<NodeTuple>();
                for (NodeTuple tuple : value) {
                    ScalarNode keyNode = (ScalarNode) tuple.getKeyNode();
                    if (keyNode.getValue().equals("color")) {
                        ScalarNode valueNode = (ScalarNode) tuple.getValueNode();
                        JavaBeanWithStaticState.color = valueNode.getValue();
                    } else if (keyNode.getValue().equals("type")) {
                        ScalarNode valueNode = (ScalarNode) tuple.getValueNode();
                        JavaBeanWithStaticState.setType(valueNode.getValue());
                    } else
                        removed.add(tuple);
                }
                beanNode.setValue(removed);
                JavaBeanWithStaticState bean = (JavaBeanWithStaticState) super
                        .constructObject(beanNode);

                return bean;
            } else {
View Full Code Here

        }

        private class ConstructCircle extends AbstractConstruct {
            @SuppressWarnings("unchecked")
            public Object construct(Node node) {
                MappingNode mnode = (MappingNode) node;
                Map<Object, Object> values = constructMapping(mnode);
                Circle circle = new Circle((Map<String, Integer>) values.get("center"),
                        (Integer) values.get("radius"));
                return circle;
            }
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.nodes.MappingNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.