<commit_before>/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.maven.plugins;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ConfigurationElementImpl implements ConfigurationElement
{
   private String name;
   private String text;
   private List<PluginElement> children = new ArrayList<>();
   private Map<String, String> attributes;

   public void setName(String name)
   {
      this.name = name;
   }

   public void setText(String text)
   {
      this.text = text;
   }

   @Override
   public String getName()
   {
      return name;
   }

   @Override
   public boolean isPlugin()
   {
      return name.equals("plugin");
   }

   @Override
   public boolean hasChildren()
   {
      return children != null && children.size() > 0;
   }

   @Override
   public String getText()
   {
      return text;
   }

   public void addChild(PluginElement element)
   {
      children.add(element);
   }

   @Override
   public List<PluginElement> getChildren()
   {
      return children;
   }

   public void setChildren(List<PluginElement> children)
   {
      this.children = children;
   }

   @Override
   public boolean hasChildByContent(String content, boolean directChildsOnly)
   {
      return hasConfigElementByContentRecursive(this, content, FilterType.CONTENT, directChildsOnly);
   }

   @Override
   public boolean hasChildByContent(String content)
   {
      return hasChildByContent(content, false);
   }

   @Override
   public ConfigurationElement getChildByContent(String content, boolean directChildsOnly)
   {
      return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, directChildsOnly);
   }

   @Override
   public ConfigurationElement getChildByContent(String content)
   {
      return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, false);
   }

   @Override
   public boolean hasChildByName(String name, boolean directChildsOnly)
   {
      return hasConfigElementByContentRecursive(this, name, FilterType.NAME, directChildsOnly);
   }

   @Override
   public boolean hasChildByName(String name)
   {
      return hasConfigElementByContentRecursive(this, name, FilterType.NAME, false);
   }

   @Override
   public ConfigurationElement getChildByName(String name, boolean directChildsOnly)
   {
      return getConfigElementRecursiveByContent(this, name, FilterType.NAME, directChildsOnly);
   }

   @Override
   public ConfigurationElement getChildByName(String name)
   {
      return getConfigElementRecursiveByContent(this, name, FilterType.NAME, false);
   }

   Map<String, String> getMutableAttributes()
   {
      if (attributes == null)
         attributes = new HashMap<String, String>();
      return attributes;
   }

   @Override
   public Map<String, String> getAttributes()
   {
      if (attributes == null)
         return Collections.emptyMap();
      else
         return Collections.unmodifiableMap(attributes);
   }

   @Override<commit_msg>FORGE-2032: Using TreeMap to keep the attribute order<commit_after>/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

package org.jboss.forge.addon.maven.plugins;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class ConfigurationElementImpl implements ConfigurationElement
{
   private String name;
   private String text;
   private List<PluginElement> children = new ArrayList<>();
   private Map<String, String> attributes;

   public void setName(String name)
   {
      this.name = name;
   }

   public void setText(String text)
   {
      this.text = text;
   }

   @Override
   public String getName()
   {
      return name;
   }

   @Override
   public boolean isPlugin()
   {
      return name.equals("plugin");
   }

   @Override
   public boolean hasChildren()
   {
      return children != null && children.size() > 0;
   }

   @Override
   public String getText()
   {
      return text;
   }

   public void addChild(PluginElement element)
   {
      children.add(element);
   }

   @Override
   public List<PluginElement> getChildren()
   {
      return children;
   }

   public void setChildren(List<PluginElement> children)
   {
      this.children = children;
   }

   @Override
   public boolean hasChildByContent(String content, boolean directChildsOnly)
   {
      return hasConfigElementByContentRecursive(this, content, FilterType.CONTENT, directChildsOnly);
   }

   @Override
   public boolean hasChildByContent(String content)
   {
      return hasChildByContent(content, false);
   }

   @Override
   public ConfigurationElement getChildByContent(String content, boolean directChildsOnly)
   {
      return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, directChildsOnly);
   }

   @Override
   public ConfigurationElement getChildByContent(String content)
   {
      return getConfigElementRecursiveByContent(this, content, FilterType.CONTENT, false);
   }

   @Override
   public boolean hasChildByName(String name, boolean directChildsOnly)
   {
      return hasConfigElementByContentRecursive(this, name, FilterType.NAME, directChildsOnly);
   }

   @Override
   public boolean hasChildByName(String name)
   {
      return hasConfigElementByContentRecursive(this, name, FilterType.NAME, false);
   }

   @Override
   public ConfigurationElement getChildByName(String name, boolean directChildsOnly)
   {
      return getConfigElementRecursiveByContent(this, name, FilterType.NAME, directChildsOnly);
   }

   @Override
   public ConfigurationElement getChildByName(String name)
   {
      return getConfigElementRecursiveByContent(this, name, FilterType.NAME, false);
   }

   Map<String, String> getMutableAttributes()
   {
      if (attributes == null)
         attributes = new TreeMap<String, String>();
      return attributes;
   }

   @Override
   public Map<String, String> getAttributes()
   {
      if (attributes == null)
         return Collections.emptyMap();
      else
         return Collections.unmodifiableMap(attributes);
   }

   @Override
{'fraction_non_alphanumeric': 0.09085402786190187, 'fraction_numerical': 0.003331314354936402, 'mean_word_length': 3.4239785666443403, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '21996', 'n_tokens_mistral': 1916, 'n_tokens_neox': 1858, 'n_words': 456}