<commit_before>package xmlcomponents.complex;

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

import org.w3c.dom.NodeList;

import xmlcomponents.JinqException;
import xmlcomponents.Jode;
import xmlcomponents.JodeFilter;

public class ExtendedNodeList implements NodeList, Iterable<ExtendedNode> {

	private List<ExtendedNode> jodes;

	public ExtendedNodeList(NodeList list) {
		this(list, false);
	}

	public ExtendedNodeList(NodeList list, boolean retainWhitespace) {
		jodes = new ArrayList<ExtendedNode>(list.getLength());
		for (int i = 0; i < list.getLength(); i++) {
			ExtendedNode toAdd = new ExtendedNode(list.item(i));
			if (!toAdd.isWhiteSpace() || retainWhitespace) {
				jodes.add(toAdd);
			}
		}
	}

	private ExtendedNodeList(List<ExtendedNode> jodes) {
		this.jodes = jodes;
	}

	public ExtendedNode first() {
		if (getLength() == 0)
			throw new JinqException("There is no first node");
		return item(0);
	}

	public ExtendedNode single(String nodeName) {
		ExtendedNodeList lst = this.filter(nodeName);
		if (lst.getLength() != 1)
			throw new JinqException("The call to 'single' did not return 1 result.");
		return lst.item(0);
	}

	public ExtendedNode single(JodeFilter filter) {
		ExtendedNodeList lst = this.filter(filter);
		if (lst.getLength() != 1)
			throw new JinqException("The call to 'single' did not return 1 result.");
		return lst.item(0);
	}

	public ExtendedNodeList filter(final String nodeName) {
		return this.filter(new JodeFilter() {
			@Override
			public boolean accept(Jode j) {
				return j.extend().getNodeName().equals(nodeName);
			}
		});
	}

	public ExtendedNodeList filter(JodeFilter filter) {
		List<ExtendedNode> result = new ArrayList<ExtendedNode>();
		for (ExtendedNode j : this) {
			if (filter.accept(new Jode(j))) {
				result.add(j);
			}
		}
		return new ExtendedNodeList(result);
	}

	@Override
	public int getLength() {
		return jodes.size();
	}

	@Override
	public ExtendedNode item(int arg0) {
		return jodes.get(arg0);
	}

	@Override
	public Iterator<ExtendedNode> iterator() {
		return jodes.iterator();
	}
}<commit_msg>Fixed ExtenededNodeList item(int) method.  MAde to comply with the documentation.<commit_after>package xmlcomponents.complex;

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

import org.w3c.dom.NodeList;

import xmlcomponents.JinqException;
import xmlcomponents.Jode;
import xmlcomponents.JodeFilter;

public class ExtendedNodeList implements NodeList, Iterable<ExtendedNode> {

   private List<ExtendedNode> jodes;

   public ExtendedNodeList(NodeList list) {
      this(list, false);
   }

   public ExtendedNodeList(NodeList list, boolean retainWhitespace) {
      jodes = new ArrayList<ExtendedNode>(list.getLength());
      for (int i = 0; i < list.getLength(); i++) {
         ExtendedNode toAdd = new ExtendedNode(list.item(i));
         if (!toAdd.isWhiteSpace() || retainWhitespace) {
            jodes.add(toAdd);
         }
      }
   }

   private ExtendedNodeList(List<ExtendedNode> jodes) {
      this.jodes = jodes;
   }

   public ExtendedNode first() {
      if (getLength() == 0)
         throw new JinqException("There is no first node");
      return item(0);
   }

   public ExtendedNode single(String nodeName) {
      ExtendedNodeList lst = this.filter(nodeName);
      if (lst.getLength() != 1)
         throw new JinqException("The call to 'single' did not return 1 result.");
      return lst.item(0);
   }

   public ExtendedNode single(JodeFilter filter) {
      ExtendedNodeList lst = this.filter(filter);
      if (lst.getLength() != 1)
         throw new JinqException("The call to 'single' did not return 1 result.");
      return lst.item(0);
   }

   public ExtendedNodeList filter(final String nodeName) {
      return this.filter(new JodeFilter() {
         @Override
         public boolean accept(Jode j) {
            return j.extend().getNodeName().equals(nodeName);
         }
      });
   }

   public ExtendedNodeList filter(JodeFilter filter) {
      List<ExtendedNode> result = new ArrayList<ExtendedNode>();
      for (ExtendedNode j : this) {
         if (filter.accept(new Jode(j))) {
            result.add(j);
         }
      }
      return new ExtendedNodeList(result);
   }

   @Override
   public int getLength() {
      return jodes.size();
   }

   @Override
   public ExtendedNode item(int arg0) {
      if (arg0 >= getLength() || arg0 < 0)
         return null;
      return jodes.get(arg0);
   }

   @Override
   public Iterator<ExtendedNode> iterator() {
      return jodes.iterator();
   }
}
{'fraction_non_alphanumeric': 0.11601129698023029, 'fraction_numerical': 0.005865739734955464, 'mean_word_length': 3.418426103646833, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '667930', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1411, 'n_words': 360}