I need to write a binary tree to HDFS, which i will use to represent a desicion tree. But in order to do that i first need to create a BinaryTreeNode class, which will be the tree node. These are my class attributes:
private String name;
private String attribute;
private String attType;
private String condition;
private String lines;
private BinaryTreeNode leftChild;
private BinaryTreeNode rightChild;
So now i need to implement the write and readFields methods for reading and writing these nodes. These are what i have done:
public void write(DataOutput d) throws IOException
{
d.writeUTF(name);
d.writeUTF(attribute);
d.writeUTF(attType);
d.writeUTF(condition);
d.writeUTF(lines);
//SOMETHIN FOR LEFT AND RIGHT CHILD
}
public void readFields(DataInput di) throws IOException
{
name=di.readUTF();
attribute=di.readUTF();
attType=di.readUTF();
condition=di.readUTF();
lines=di.readUTF();
//SOMETHIN FOR LEFT AND RIGHT CHILD
}
BinaryTreeNode read(DataInput in) throws IOException
{
BinaryTreeNode ob = new BinaryTreeNode();
ob.readFields(in);
return ob;
}
What i cant think of is how to write and read my 2 child nodes. Note that the tree is going to be build recursively and every node will have 0-2 childs. So my later purpose is to have a BinaryTree class that will have the attribute BinaryTreeNode root. Thanks