<commit_before>package org.exist.fluent;

import javax.xml.XMLConstants;

import org.w3c.dom.*;
import org.w3c.dom.Document;

/**
 * A qualified name, consisting of a namespace and a local name.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class QName extends javax.xml.namespace.QName implements Comparable<QName> {
	
	private final String tag;
	
	/**
	 * Create a qualified name.
	 *
	 * @param namespace the namespace of the qualified name, <code>null</code> if none
	 * @param localName the local part of the qualified name, must not be <code>null</code> or empty
	 * @param prefix the prefix to use for the qualified name, <code>null</code> if default (empty) prefix
	 */
	public QName(String namespace, String localName, String prefix) {
		super(namespace == null ? XMLConstants.NULL_NS_URI : namespace, localName, prefix == null ? XMLConstants.DEFAULT_NS_PREFIX : prefix);
		if (localName == null || localName.length() == 0) throw new IllegalArgumentException("null or empty local name");
		if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
			tag = localName;
		} else {
			tag = prefix + ":" + localName;
		}
	}
		
	@Override public int compareTo(QName o) {
		return toString().compareTo(o.toString());
	}

	/**
	 * Return whether this qualified name is actually qualified by a namespace or not.
	 *
	 * @return <code>true</code> if the qualified name has a namespace set, <code>false</code> if it's just a local name
	 */
	public boolean hasNamespace() {
		return !getNamespaceURI().equals(XMLConstants.NULL_NS_URI);
	}
	
	/**
	 * Create an element in the given document whose tag is this qualified name.  Correctly calls
	 * <code>createElement</code> or <code>createElementNS</code> depending on whether
	 * this name is actually qualified or not.
	 * 
	 * @param doc the document to use to create the element
	 * @return a new element whose tag is this qualified name
	 */
	public Element createElement(Document doc) {
		if (hasNamespace()) return doc.createElementNS(getNamespaceURI(), tag);
		return doc.createElement(tag);
	}
	
	/**
	 * Create an attribute in the given document whose name is this qualified name.  Correctly calls
	 * <code>createAttribute</code> or <code>createAttributeNS</code> depending on whether
	 * this name is actually qualified or not.
	 * <commit_msg>Removed @Override of interface method for old compilers.<commit_after>package org.exist.fluent;

import javax.xml.XMLConstants;

import org.w3c.dom.*;
import org.w3c.dom.Document;

/**
 * A qualified name, consisting of a namespace and a local name.
 *
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class QName extends javax.xml.namespace.QName implements Comparable<QName> {
	
	private final String tag;
	
	/**
	 * Create a qualified name.
	 *
	 * @param namespace the namespace of the qualified name, <code>null</code> if none
	 * @param localName the local part of the qualified name, must not be <code>null</code> or empty
	 * @param prefix the prefix to use for the qualified name, <code>null</code> if default (empty) prefix
	 */
	public QName(String namespace, String localName, String prefix) {
		super(namespace == null ? XMLConstants.NULL_NS_URI : namespace, localName, prefix == null ? XMLConstants.DEFAULT_NS_PREFIX : prefix);
		if (localName == null || localName.length() == 0) throw new IllegalArgumentException("null or empty local name");
		if (prefix == null || prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) {
			tag = localName;
		} else {
			tag = prefix + ":" + localName;
		}
	}
		
	public int compareTo(QName o) {
		return toString().compareTo(o.toString());
	}

	/**
	 * Return whether this qualified name is actually qualified by a namespace or not.
	 *
	 * @return <code>true</code> if the qualified name has a namespace set, <code>false</code> if it's just a local name
	 */
	public boolean hasNamespace() {
		return !getNamespaceURI().equals(XMLConstants.NULL_NS_URI);
	}
	
	/**
	 * Create an element in the given document whose tag is this qualified name.  Correctly calls
	 * <code>createElement</code> or <code>createElementNS</code> depending on whether
	 * this name is actually qualified or not.
	 * 
	 * @param doc the document to use to create the element
	 * @return a new element whose tag is this qualified name
	 */
	public Element createElement(Document doc) {
		if (hasNamespace()) return doc.createElementNS(getNamespaceURI(), tag);
		return doc.createElement(tag);
	}
	
	/**
	 * Create an attribute in the given document whose name is this qualified name.  Correctly calls
	 * <code>createAttribute</code> or <code>createAttributeNS</code> depending on whether
	 * this name is actually qualified or not.
	 * 
{'fraction_non_alphanumeric': 0.1083670427932723, 'fraction_numerical': 0.0012774111134766872, 'mean_word_length': 4.117647058823529, 'pattern_counts': {'":': 2, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '1685043', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1297, 'n_words': 496}