This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes Tree API? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tree API?" Watch "Tree API?" New topic

Tree API?

Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Howdy Ranchers,

I was wondering if any one can point me to a package or framework for working with objects that are linked in a tree structure. I know all about TreeSet and TreeMap, but those are data structures that are backed by trees. What I'm looking for are interfaces and utility classes that explicitly expose and utilize the tree-like references among a group of objects. Something along the lines of ...

TreeNode node = ...;, "search query");

Is there such a package? Or does everyone end up writing their own little BFS and DFS tree search algorithms?

Fun programming etcetera!
Rob Spoor

Joined: Oct 27, 2005
Posts: 20183

Do you see those little dashes under your "TreeNode"? That means that it was found in the Java API. If you click on it you will see that interface, and it's probably exactly what you want. You can use DefaultMutableTreeNode as the concrete implementing class.

How To Ask Questions How To Answer Questions
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Thanks, Rob. I took a look at the API for TreeNode and DefaultMutableTreeNode. I see how I could use those classes to build a tree data structure. What I wasn't able to find were any utility classes used to search through a tree of TreeNodes. Anybody know of any global tree search implementations in any of the Java packages or ancillary frameworks?
Paul Clapham

Joined: Oct 14, 2005
Posts: 19850

Why would you need a "utility class" when DefaultMutableTreeNode already contains methods named breadthFirstEnumeration and depthFirstEnumeration?
Dave Wingate
Ranch Hand

Joined: Mar 26, 2002
Posts: 262
Doh! I failed to notice those methods. Many thanks for your patience.
I agree. Here's the link:
subject: Tree API?
jQuery in Action, 3rd edition