<commit_before>/*
 * $Id$
 */
package org.xins.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.xins.common.collections.BasicPropertyReader;

/**
 * The data element received from the server when any.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 *
 * @since XINS 0.203
 */
public class DataElement {

   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructors
   //-------------------------------------------------------------------------

   /**
    * Creates a new DataElement with the specified qualified name.
    *
    * @param qName
    *    the name of the element, cannot be <code>null</code>.
    */
   DataElement(String qName) {
      _name = qName;
      _children = new ArrayList();
      _attributes = new BasicPropertyReader();
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   /**
    * The name of this element.
    */
   private final String _name;

   /**
    * The sub-elements of this element.
    */
   private final List _children;

   /**
    * The attributes of this elements.
    */
   private final BasicPropertyReader _attributes;

   /**
    * The content of this element.
    */
   private String _pcdata;

   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Gets the name of the element.
    *
    * @return element
    *    the name of this element, cannot be <code>null</code>.
    */
   public String getName() {
      return _name;
   }

   /**
    * Adds a new child to this element.
    *
    * @param element
    *    the new child to add to this element, cannot be <code>null</code>.
    */
   void addChild(DataElement element) {
      _children.add(element);
   }

   /**
    * Adds an attribute to this element. If the key already exists, the previous
    * value for this key is replaced by the new one.
    *
    * @param key
    *    the name of the attribute, cannot be <code>null</code>.
    * @param value
    *    the value of the attribute, can be <code>null</code>.
    */
   void addAttribute(String key, String value) {
      _attributes.set(key, value);
   }

   /**
    * Sets the content of this element.
    *
    * @param pcdata
    *    the text content for this element, can be <code>null</code>.
    */
   void setPCData(String pcdata) {
      _pcdata = pcdata;
   }

   /**
    * Gets the list of the attributes.
    *
    * @return
    *    an iterator containing where each item is a name of an attribute as String.
    */
   public Iterator getAttributes() {
      return _attributes.getNames();
   }

   /**
    * Gets the value of an attribute.
    *
    * @param name
    *    the name of the attribute, cannot be <code>null</code>.
    *
    * @return
    *    the value of the attribute, or <code>null</code> if not set or set to <code>null</code>.
    */
    public String get(String name) {
       return _attributes.get(name);
    }

    /**
     * Gets the children of this element.
     *
     * @return
     *    an iterator containing the children of this element as DataElement.
     */
    public Iterator getChildren() {
       return _children.iterator();
    }
<commit_msg>Improved documentation. Renamed setPCData to setText.<commit_after>/*
 * $Id$
 */
package org.xins.client;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.xins.common.collections.BasicPropertyReader;

/**
 * The data element received from the server when any.
 *
 * @version $Revision$ $Date$
 * @author <NAME> (<a href="mailto:<EMAIL>"><EMAIL></a>)
 *
 * @since XINS 0.203
 */
public class DataElement {

   //-------------------------------------------------------------------------
   // Class fields
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Class functions
   //-------------------------------------------------------------------------

   //-------------------------------------------------------------------------
   // Constructors
   //-------------------------------------------------------------------------

   /**
    * Creates a new DataElement with the specified qualified name.
    *
    * @param qName
    *    the name of the element, cannot be <code>null</code>.
    */
   DataElement(String qName) {
      _name = qName;
      _children = new ArrayList();
      _attributes = new BasicPropertyReader();
   }


   //-------------------------------------------------------------------------
   // Fields
   //-------------------------------------------------------------------------

   /**
    * The name of this element.
    */
   private final String _name;

   /**
    * The sub-elements of this element.
    */
   private final List _children;

   /**
    * The attributes of this elements.
    */
   private final BasicPropertyReader _attributes;

   /**
    * The content of this element.
    */
   private String _pcdata;

   //-------------------------------------------------------------------------
   // Methods
   //-------------------------------------------------------------------------

   /**
    * Gets the name of the element.
    *
    * @return element
    *    the name of this element, cannot be <code>null</code>.
    */
   public String getName() {
      return _name;
   }

   /**
    * Adds a new child to this element.
    *
    * @param element
    *    the new child to add to this element, cannot be <code>null</code>.
    */
   void addChild(DataElement element) {
      _children.add(element);
   }

   /**
    * Adds an attribute to this element. If the key already exists, the previous
    * value for this key is replaced by the new one.
    *
    * @param key
    *    the name of the attribute, cannot be <code>null</code>.
    *
    * @param value
    *    the value of the attribute, can be <code>null</code>.
    */
   void addAttribute(String key, String value) {
      _attributes.set(key, value);
   }

   /**
    * Sets the PCDATA content of this element.
    *
    * @param pcdata
    *    the PCDATA content for this element, can be <code>null</code>.
    */
   void setText(String pcdata) {
      _pcdata = pcdata;
   }

   /**
    * Gets the list of the attributes.
    *
    * @return
    *    an {@link Iterator} returning each attribute name as a
    *    {@link String}; <code>null</code> indicates there are no attributes.
    */
   public Iterator getAttributes() {
      return _attributes.getNames();
   }

   /**
    * Gets the value of an attribute.
    *
    * @param name
    *    the name of the attribute, cannot be <code>null</code>.
    *
    * @return
    *    the value of the attribute, or <code>null</code> if the attribute is
    *    either not set or set to <code>null</code>.
    */
    public String get(String name) {
       return _attributes.get(name);
    }

    /**
     * Gets the children of this element.
     *
     * @return
     *    an {@link Iterator} that returns each child of this element as
     *    another <code>DataElement</code> instance; <code>null</code>
     *    indicates there are no child elements.
     */
    public Iterator getChildren() {
       return _children.iterator();
    }

{'fraction_non_alphanumeric': 0.2795385395537525, 'fraction_numerical': 0.0010141987829614604, 'mean_word_length': 1.2116624614522007, 'pattern_counts': {'":': 0, '<': 55, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '3137211', 'n_tokens_mistral': 2005, 'n_tokens_neox': 1953, 'n_words': 648}