<commit_before>/**
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-Nürnberg
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.
 */
package org.sweble.wom3.impl;

/**
 * DOM v1 Attribute Implementation (no namespace awareness)
 */
public class AttributeImpl
		extends
			AttributeBase
{
	private static final long serialVersionUID = 1L;
	
	/**
	 * This value must always be normalized.
	 */
	private String strValue;
	
	private Object value;
	
	// =========================================================================
	
	/**
	 * For AttributeNsImpl only!
	 */
	AttributeImpl(DocumentImpl owner)
	{
		super(owner);
	}
	
	protected AttributeImpl(DocumentImpl owner, String name)
	{
		super(owner);
		setName(name);
	}
	
	// =========================================================================
	
	@Override
	public String getValue()
	{
		return strValue;
	}
	
	public void setValue(Object value, String strValue)
	{
		this.value = (value != null) ? value : strValue;
		this.strValue = (strValue != null) ? strValue : (String) value;
	}
	
	protected Object getNativeValue()
	{
		return value;
	}
	
	// =========================================================================
	
	@Override
	protected Object clone() throws CloneNotSupportedException
	{
		AttributeImpl newNode = (AttributeImpl) super.clone();
		/* FIXME: This is horribly flawed....
		 * One cannot clone arbitrary objects, but if we just copy the other objects
		 * value, non-immutable values can have bad side effects since a change in one would affect all clones as well...
		if (this.value != null)
			newNode.value = this.value.clone();
		*/
		return newNode;
	}
}
<commit_msg>Hopefully fixed messy implementation of AttributeImpl.clone<commit_after>/**
 * Copyright 2011 The Open Source Research Group,
 *                University of Erlangen-Nürnberg
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see http://www.gnu.org/licenses/.
 */
package org.sweble.wom3.impl;

/**
 * DOM v1 Attribute Implementation (no namespace awareness)
 */
public class AttributeImpl
		extends
			AttributeBase
{
	private static final long serialVersionUID = 1L;
	
	/**
	 * This value must always be normalized.
	 */
	private String strValue;
	
	private Object value;
	
	// =========================================================================
	
	/**
	 * For AttributeNsImpl only!
	 */
	AttributeImpl(DocumentImpl owner)
	{
		super(owner);
	}
	
	protected AttributeImpl(DocumentImpl owner, String name)
	{
		super(owner);
		setName(name);
	}
	
	// =========================================================================
	
	@Override
	public String getValue()
	{
		return strValue;
	}
	
	public void setValue(Object value, String strValue)
	{
		this.value = (value != null) ? value : strValue;
		this.strValue = (strValue != null) ? strValue : (String) value;
	}
	
	protected Object getNativeValue()
	{
		return value;
	}
	
	// =========================================================================
	
	@Override
	protected Object clone() throws CloneNotSupportedException
	{
		AttributeImpl newNode = (AttributeImpl) super.clone();
		
		// We MUST NOT clone the native value. It might be a mutable object!
		// Well, to be honest, we cannot even clone it if we wanted...
		if (value != null)
		{
			BackboneElement parent = (BackboneElement) getOwnerElement();
			
			AttributeDescriptor descriptor = parent.getAttributeDescriptorOrFail(
					getNamespaceURI(),
					getLocalName(),
					getName());
			
			NativeAndStringValuePair verified = new NativeAndStringValuePair(strValue);
			descriptor.verifyAndConvert(parent, verified);
			
			newNode.value = verified.value;
		}
		
		return newNode;
	}
}

{'fraction_non_alphanumeric': 0.16666666666666666, 'fraction_numerical': 0.003256003256003256, 'mean_word_length': 3.832841691248771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2894020', 'n_tokens_mistral': 1410, 'n_tokens_neox': 1238, 'n_words': 491}