TREENODE for Tree

package com.zx.views.tree;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class TreeNode
{
private String name;

private String key;

private List<TreeNode> children;

public TreeNode( String name , String key )
{
this.name = name;
this.key = key;
}

public String getName ( )
{
return name;
}

public void setChildren ( List<TreeNode> children )
{
this.children = children;
}

public List<TreeNode> getChildren ( )
{
return this.children;
}

public String toString ( )
{
return getName();
}

public Object getAdapter ( Class key )
{
return null;
}

public String getKey ( )
{
return key;
}

public void setKey ( String key )
{
this.key = key;
}

public TreeNode findChild ( String nodeName )
{
if ( children == null ) return null;
for ( Iterator<TreeNode> it = children.iterator() ; it.hasNext() ; )
{
if ( (it.next()).getName().equals(nodeName) ) { return it.next(); }
}
return null;
}

public boolean isLeaf ( )
{
return children == null || children.size() == 0;
}

public void addChild ( TreeNode child )
{
if ( children == null ) children = new ArrayList<TreeNode>();
children.add(child);
}

public void removeChild ( TreeNode child )
{
children.remove(child);
}

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章