8
I have list of Objects T, it has a property of parent where the top objects parent property is null. I want to put all the objects into a TreeSet (or TreeMap). Top level objects will be all the root objects that has no parent (parent is null) and they will have their children under them.
Something like this
o
/ | \
Ra Rb Rc -- Level Root Objects
/ | \ | \
Ca1 Ca2 Cb1 Cc1 Cc2 -- Level of First Children
/ \
Ca11 Ca12.............. -- Level of Second Children
So I can get Ra and find its children (Ca1, Ca2, Ca11, Ca12....)
Update: Sorry may be it wasn't clear, nodes point to parents and if parent is null, they are root nodes. The problem is parents need to know its children. But the relationship is in the opposite direction.
class Node
{
private Node parent;
private String name;
}