public void addChild(Links child) { children.add(child); }
public void addChild(Links child)
{
children.add(child);
}
public boolean hasChild(Links child)
{
return children.contains(child);
}
public boolean removeChild(Links child)
{
return children.remove(child);
}
public boolean isLeaf()
{
return children.size() <= 0;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((nodeName == null) ? 0 : nodeName.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Links other = (Links) obj;
if (nodeName == null) {
if (other.nodeName != null)
return false;
}
else if (!nodeName.equals(other.nodeName)) //hint: this only works if nodeName is unique! If not, use a unique static counter
return false;
return true;
}
Edit: Just to point out, this code is not for efficiency. It is written for clarity. Do not care about efficiency before you really have to.