de.mrapp.parser.feed.common.datastructure.AttributeNode Maven / Gradle / Ivy
/*
* JavaFeedParserCommon Copyright 2013-2014 Michael Rapp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
package de.mrapp.parser.feed.common.datastructure;
import static de.mrapp.parser.feed.common.util.Condition.ensureNotNull;
/**
* A node, which represents an attribute of a feed's XML structure.
*
* @author Michael Rapp
*
* @since 1.0.0
*/
public class AttributeNode extends AbstractNode implements Attribute {
/**
* The constant serial version UID.
*/
private static final long serialVersionUID = 1L;
/**
* The attribute's value.
*/
private String value;
/**
* Creates a new node, which represents an attribute of a feed's XML
* structure. The attribute's value is an empty string by default.
*
* @param name
* The attribute's name as a {@link String}. The name may neither
* be null, nor empty
*/
public AttributeNode(final String name) {
super(name);
setValue("");
}
@Override
public final String getValue() {
return value;
}
/**
* Sets the attribute's value.
*
* @param value
* The value, which should be set, as a {@link String}. The value
* may not be null
*/
public final void setValue(final String value) {
ensureNotNull(value, "The value may not be null");
this.value = value;
}
@Override
public final Attribute clone() throws CloneNotSupportedException {
AttributeNode clonedAttributeNode = new AttributeNode(getName());
clonedAttributeNode.setValue(getValue());
clonedAttributeNode.setNamespace(getNamespace().clone());
return clonedAttributeNode;
}
@Override
public final String toString() {
return "AttributeNode [name=" + getName() + ", value=" + value
+ ", namespace=" + getNamespace() + "]";
}
@Override
public final int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + value.hashCode();
return result;
}
@Override
public final boolean equals(final Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
AttributeNode other = (AttributeNode) obj;
if (!value.equals(other.value))
return false;
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy