Example usage for org.apache.commons.configuration2.tree ImmutableNode getNodeName

List of usage examples for org.apache.commons.configuration2.tree ImmutableNode getNodeName

Introduction

In this page you can find the example usage for org.apache.commons.configuration2.tree ImmutableNode getNodeName.

Prototype

public String getNodeName() 

Source Link

Document

Returns the name of this node.

Usage

From source file:com.virtlink.commons.configuration2.jackson.JacksonConfiguration.java

private Map<String, List<ImmutableNode>> getChildrenWithName(final ImmutableNode node) {
    final Map<String, List<ImmutableNode>> children = new HashMap<>();
    for (final ImmutableNode child : node.getChildren()) {
        final String name = child.getNodeName();
        if (!children.containsKey(name)) {
            children.put(name, new ArrayList<ImmutableNode>());
        }/*from  www  .  ja v  a  2 s .c o  m*/
        children.get(name).add(child);
    }
    return children;
}

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricherTest.java

private Map<String, Object> constructMap(ImmutableNode node) {
    final Map<String, Object> map = new HashMap<>(node.getChildren().size());
    map.putAll(node.getAttributes());/*w  w  w  . j  ava  2s  . c  om*/

    MutableListMultimap<String, ImmutableNode> nodesByName = ListAdapter.adapt(node.getChildren())
            .groupBy(new Function<ImmutableNode, String>() {
                @Override
                public String valueOf(ImmutableNode immutableNode) {
                    return immutableNode.getNodeName();
                }
            });
    nodesByName.forEachKeyMultiValues(new Procedure2<String, Iterable<ImmutableNode>>() {
        @Override
        public void value(String nodeName, Iterable<ImmutableNode> nodeIterable) {
            //            System.out.println("At node " + cNode.getNodeName() + " and attrs " + cNode.getAttributes() + " and value " + cNode.getValue() + " and children " + cNode.getChildren());
            MutableList<ImmutableNode> nodes = CollectionAdapter.wrapList(nodeIterable);
            if (nodes.size() > 1) {
                map.put(nodeName, nodes.collect(new Function<ImmutableNode, Object>() {
                    @Override
                    public Object valueOf(ImmutableNode node1) {
                        return DbEnvironmentXmlEnricherTest.this.getNodeValue(node1);
                    }
                }));
            } else {
                map.put(nodeName, DbEnvironmentXmlEnricherTest.this.getNodeValue(nodes.getFirst()));
            }
        }
    });
    return map;
}