com.datastax.data.tree.Dendrogram Maven / Gradle / Ivy
package com.datastax.data.tree;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* UserItem: Anders Hong
* Date: 10/12/12
* Time: 12:59 PM
*/
public class Dendrogram implements Serializable {
private String name;
private String value;
private int size=6000;
private static final long serialVersionUID = 1L;
private List children;
private Dendrogram parent;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public List getChildren() {
return children;
}
public void setChildren(List children) {
this.children = children;
}
public void addChild(Dendrogram child){
if(this.parent==null){
addChild(this,child);
}else {
Dendrogram existed=this.parent.getByName(this.getName());
addChild(existed,child);
}
}
public void addChild(Dendrogram parent, Dendrogram child){
if(parent.children==null){
parent.setChildren(new ArrayList());
}
if(!parent.hasChild(child)){
parent.getChildren().add(child);
}
child.setParent(parent);
}
public Dendrogram getByName(String name){
for(Dendrogram c:getChildren()){
if(c.getName().equals(name)){
return c;
}
}
return null;
}
public boolean hasChild(Dendrogram child){
if(children==null) return false;
for(Dendrogram d : children){
if(d.equals(child)){
return true;
}
}
return false;
}
@Override
public boolean equals(Object obj) {
Dendrogram dendrogram=(Dendrogram) obj;
return dendrogram.getName().equals(this.getName());
}
public void setParent(Dendrogram parent) {
this.parent = parent;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
}