looking for a "family tree" data type

H

Henry Townsend

Is there a standard Java tree structure which allows the programmer to
attach nodes to parent nodes? Basically I need to represent something
like a family tree (actually it's a process tree but the logic is the
same). For each new node I will know, or have a way of determining,
which pre-existing node is its parent and just need to attach it there,
and subsequently have a means of traversing it.

Everything tree-related I can find in java.* is either a GUI/display
class(like JTree) or has a "natural ordering" like java.util.TreeSet
which does not allow the user to pick the parent.

Of course I could implement something myself by making each object hold
a reference to its parent and a list of references to its children etc,
but would prefer to use something built-in, documented, and stable. Does
a class like this exist?

Thanks,
HT
 
W

Wildemar Wildenburger

Henry said:
Everything tree-related I can find in java.* is either a GUI/display
class(like JTree) or has a "natural ordering" like java.util.TreeSet
which does not allow the user to pick the parent.
The javax.tree package has the DefaultTreeModel. While it is meant as a
model for display, you could very well just use that as a
data-structure; no need for any GUI if you don't want to.

My two humble cents.

/W
 
L

Lew

Wildemar said:
The javax.tree package has the DefaultTreeModel. While it is meant as a
model for display, you could very well just use that as a
data-structure; no need for any GUI if you don't want to.

My two humble cents.

Better to roll your own.
 
J

Jeff Higgins

Henry said:
Is there a standard Java tree structure which allows the programmer to
attach nodes to parent nodes?
[snip]
but would prefer to use something built-in, documented, and stable. Does
a class like this exist?

How about documented, not built in, and not stable?
<https://jsfcompounds.dev.java.net/>
See the subproject treeutils.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top