aspose file tools*
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Tree API?" Watch "Tree API?" New topic
Author

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 = ...;
SomeUtilityClass.search(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
Sheriff

Joined: Oct 27, 2005
Posts: 19723
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
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
Bartender

Joined: Oct 14, 2005
Posts: 18672
    
    8

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Tree API?