<commit_before>package com.crawljax.core.state;

import com.crawljax.util.Helper;

import org.w3c.dom.Node;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * This class represents an element. It is built from the node name and node text contents.
 * 
 * @author mesbah
 * @author <NAME> <<EMAIL>>
 * @version $Id$
 */
public class Element implements Serializable {

	private static final long serialVersionUID = -1608999189549530008L;
	private static final int HASHCONST = 32;

	private Node node;
	private long id;
	private String tag;
	private String text;
	private List<Attribute> attributes = new ArrayList<Attribute>();

	/**
	 * Default constructor to support saving instances of this class as an XML.
	 */
	public Element() {

	}

	/**
	 * Create a new Element.
	 * 
	 * @param node
	 *            the node used to retrieve the name and the text content from
	 */
	public Element(Node node) {
		if (node != null) {
			this.node = node;
			this.tag = node.getNodeName();
			if (node.getTextContent() == null) {
				this.text = "";
			} else {
				this.text = Helper.removeNewLines(node.getTextContent()).trim();
			}
			attributes = new ArrayList<Attribute>();
			for (int i = 0; i < node.getAttributes().getLength(); i++) {
				Node attr = node.getAttributes().item(i);
				Attribute attribute = new Attribute(attr.getNodeName(), attr.getNodeValue());
				attributes.add(attribute);
			}
		}

	}

	@Override
	public String toString() {
		StringBuffer str = new StringBuffer();
		if (!this.getText().equals("")) {
			str.append("\"");
			str.append(getText());
			str.append("\" ");
		}
		str.append(getTag().toUpperCase());
		str.append(":");
		if (getAttributes() != null) {
			for (Attribute attribute : getAttributes()) {
				str.append(" ");
				str.append(attribute.toString());
			}
		}
		return str.toString();
	}

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object instanceof Element)) {
			return false;
		}
		return toString().equals(((Element) object).toString());
	}

	@Override
	public int hashCode() {

		final int prime = 31;
		int result = 1;
		result = prime * result;
		if (attributes != null) {
			result += attributes.hashCode();
		}
		result = prime * result + (int) (id ^ (id >>> HASHCONST));
		result = prime * result;
		if (node != null) {
			result += node.hashCode();
		}
		result = prime * result;
		if (tag != null) {
			tag.hashCode();
		}
		result = prime * result;
		if (text != null) {
			text.hashCode();
		}
		return result;
	}

	/**
	 * Are all the attributes the same?
	 * 
	 * @param otherElement
	 *            the other element to compare
	 * @return true if the other attributes are equal to this one.
	 */<commit_msg>Fixed an other findbugs issue<commit_after>package com.crawljax.core.state;

import com.crawljax.util.Helper;

import org.w3c.dom.Node;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * This class represents an element. It is built from the node name and node text contents.
 * 
 * @author mesbah
 * @author <NAME> <<EMAIL>>
 * @version $Id$
 */
public class Element implements Serializable {

	private static final long serialVersionUID = -1608999189549530008L;
	private static final int HASHCONST = 32;

	private Node node;
	private long id;
	private String tag;
	private String text;
	private List<Attribute> attributes = new ArrayList<Attribute>();

	/**
	 * Default constructor to support saving instances of this class as an XML.
	 */
	public Element() {

	}

	/**
	 * Create a new Element.
	 * 
	 * @param node
	 *            the node used to retrieve the name and the text content from
	 */
	public Element(Node node) {
		if (node != null) {
			this.node = node;
			this.tag = node.getNodeName();
			if (node.getTextContent() == null) {
				this.text = "";
			} else {
				this.text = Helper.removeNewLines(node.getTextContent()).trim();
			}
			attributes = new ArrayList<Attribute>();
			for (int i = 0; i < node.getAttributes().getLength(); i++) {
				Node attr = node.getAttributes().item(i);
				Attribute attribute = new Attribute(attr.getNodeName(), attr.getNodeValue());
				attributes.add(attribute);
			}
		}

	}

	@Override
	public String toString() {
		StringBuffer str = new StringBuffer();
		if (!this.getText().equals("")) {
			str.append("\"");
			str.append(getText());
			str.append("\" ");
		}
		str.append(getTag().toUpperCase());
		str.append(":");
		if (getAttributes() != null) {
			for (Attribute attribute : getAttributes()) {
				str.append(" ");
				str.append(attribute.toString());
			}
		}
		return str.toString();
	}

	@Override
	public boolean equals(Object object) {
		if (object == null || !(object instanceof Element)) {
			return false;
		}
		return toString().equals(((Element) object).toString());
	}

	@Override
	public int hashCode() {

		final int prime = 31;
		int result = 1;
		result = prime * result;
		if (attributes != null) {
			result += attributes.hashCode();
		}
		result = prime * result + (int) (id ^ (id >>> HASHCONST));
		result = prime * result;
		if (node != null) {
			result += node.hashCode();
		}
		result = prime * result;
		if (tag != null) {
			result += tag.hashCode();
		}
		result = prime * result;
		if (text != null) {
			result += text.hashCode();
		}
		return result;
	}

	/**
	 * Are all the attributes the same?
	 * 
	 * @param otherElement
	 *            the other element to compare
	 * @return true if the other attributes are equal to this one.
	 */
{'fraction_non_alphanumeric': 0.1441016333938294, 'fraction_numerical': 0.009437386569872959, 'mean_word_length': 3.190874524714829, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 21, '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': '6339687', 'n_tokens_mistral': 1937, 'n_tokens_neox': 1683, 'n_words': 512}