// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/ContainerNode.java
// public interface ContainerNode<C extends Node> extends Node {
//     /**
//      * @return a map of child nodes
//      */
//     Map<String, C> getChildren();
// 
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/Node.java
// public interface Node {
//     /**
//      * Apply the defaults or apply some kind of inheritance in case the values of some attributes were not set
//      * explicitly. See also {@link DefaultsAndInheritanceVisitor}.
//      *
//      * @param configurationStack the stack of ancestor configuration nodes. Can be queried to inherit values.
//      */
//     void applyDefaultsAndInheritance(Stack<Node> configurationStack);
// 
//     /**
//      * @return a list of comment lines that should appear before this node
//      */
//     List<String> getCommentBefore();
// 
//     /**
//      * @return the name of the present node that is supposed to be unique within the parent node. Can be {@code null} in
//      *         case this {@link Node} is an element of a {@link NodeList}.
//      */
//     String getName();
// 
//     /**
//      * Fully reset the state of this {@link Node} using the given {@code source} {@link Node}.
//      *
//      * @param source the {@link Node} to take the values from
//      */
//     void init(Node source);
// 
//     /**
//      * @param stack the ancestor hierarchy of this {@link Node}
//      * @return {@code true} if this {@link Node}'s internal state has not been set yet or if the state is in the
//      *         instance or implementation specific default state. Otherwise returns {@code false}
//      */
//     boolean isInDefaultState(Stack<Node> stack);
// 
//     /**
//      * @return {@code true} if the name of the node will commonly contain special characters, esp. periods. Otherwise
//      *         returns {@code false}
//      */
//     boolean shouldEscapeName();
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/walk/DefaultsAndInheritanceVisitor.java
// public class DefaultsAndInheritanceVisitor extends AbstractVisitor {
// 
//     @Override
//     public boolean containerBegin(ContainerNode<? extends Node> node) {
//         super.containerBegin(node);
//         node.applyDefaultsAndInheritance(stack);
//         return true;
//     }
// 
//     @Override
//     public boolean listBegin(ListNode<? extends Node> node) {
//         super.listBegin(node);
//         node.applyDefaultsAndInheritance(stack);
//         return true;
//     }
// 
//     @Override
//     public void scalar(ScalarNode<Object> node) {
//         node.applyDefaultsAndInheritance(stack);
//     }
// 
// }


import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.srcdeps.core.config.tree.ContainerNode;
import org.srcdeps.core.config.tree.Node;
import org.srcdeps.core.config.tree.walk.DefaultsAndInheritanceVisitor;
/**
 * Copyright 2015-2018 Maven Source Dependencies
 * Plugin contributors as indicated by the @author tags.
 *
 * 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.srcdeps.core.config.tree.impl;



/**
 * The default implementation of {@link ContainerNode}.
 *
 * @author <a href="https://github.com/ppalaga">Peter Palaga</a>
 *
 * @param <C> the type of child nodes
 */
public class DefaultContainerNode<C extends Node> implements ContainerNode<C> {

    protected final Map<String, C> children = new LinkedHashMap<>();

    protected final List<String> commentBefore = new ArrayList<>();

    protected String name;

    private boolean shouldEscapeName;

    public DefaultContainerNode(String name) {
        this(name, false);
    }

    public DefaultContainerNode(String name, boolean shouldEscapeName) {
        super();
        this.name = name;
        this.shouldEscapeName = shouldEscapeName;
    }

// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/ContainerNode.java
// public interface ContainerNode<C extends Node> extends Node {
//     /**
//      * @return a map of child nodes
//      */
//     Map<String, C> getChildren();
// 
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/Node.java
// public interface Node {
//     /**
//      * Apply the defaults or apply some kind of inheritance in case the values of some attributes were not set
//      * explicitly. See also {@link DefaultsAndInheritanceVisitor}.
//      *
//      * @param configurationStack the stack of ancestor configuration nodes. Can be queried to inherit values.
//      */
//     void applyDefaultsAndInheritance(Stack<Node> configurationStack);
// 
//     /**
//      * @return a list of comment lines that should appear before this node
//      */
//     List<String> getCommentBefore();
// 
//     /**
//      * @return the name of the present node that is supposed to be unique within the parent node. Can be {@code null} in
//      *         case this {@link Node} is an element of a {@link NodeList}.
//      */
//     String getName();
// 
//     /**
//      * Fully reset the state of this {@link Node} using the given {@code source} {@link Node}.
//      *
//      * @param source the {@link Node} to take the values from
//      */
//     void init(Node source);
// 
//     /**
//      * @param stack the ancestor hierarchy of this {@link Node}
//      * @return {@code true} if this {@link Node}'s internal state has not been set yet or if the state is in the
//      *         instance or implementation specific default state. Otherwise returns {@code false}
//      */
//     boolean isInDefaultState(Stack<Node> stack);
// 
//     /**
//      * @return {@code true} if the name of the node will commonly contain special characters, esp. periods. Otherwise
//      *         returns {@code false}
//      */
//     boolean shouldEscapeName();
// }
// 
// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/walk/DefaultsAndInheritanceVisitor.java
// public class DefaultsAndInheritanceVisitor extends AbstractVisitor {
// 
//     @Override
//     public boolean containerBegin(ContainerNode<? extends Node> node) {
//         super.containerBegin(node);
//         node.applyDefaultsAndInheritance(stack);
//         return true;
//     }
// 
//     @Override
//     public boolean listBegin(ListNode<? extends Node> node) {
//         super.listBegin(node);
//         node.applyDefaultsAndInheritance(stack);
//         return true;
//     }
// 
//     @Override
//     public void scalar(ScalarNode<Object> node) {
//         node.applyDefaultsAndInheritance(stack);
//     }
// 
// }


// Path: srcdeps-core/src/main/java/org/srcdeps/core/config/tree/impl/DefaultContainerNode.java
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import org.srcdeps.core.config.tree.ContainerNode;
import org.srcdeps.core.config.tree.Node;
import org.srcdeps.core.config.tree.walk.DefaultsAndInheritanceVisitor;

/**
 * Copyright 2015-2018 Maven Source Dependencies
 * Plugin contributors as indicated by the @author tags.
 *
 * 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.srcdeps.core.config.tree.impl;



/**
 * The default implementation of {@link ContainerNode}.
 *
 * @author <a href="https://github.com/ppalaga">Peter Palaga</a>
 *
 * @param <C> the type of child nodes
 */
public class DefaultContainerNode<C extends Node> implements ContainerNode<C> {

    protected final Map<String, C> children = new LinkedHashMap<>();

    protected final List<String> commentBefore = new ArrayList<>();

    protected String name;

    private boolean shouldEscapeName;

    public DefaultContainerNode(String name) {
        this(name, false);
    }

    public DefaultContainerNode(String name, boolean shouldEscapeName) {
        super();
        this.name = name;
        this.shouldEscapeName = shouldEscapeName;
    }

    public void addChild(C child) {