File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Parsing a  TreeModel structure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Parsing a  TreeModel structure" Watch "Parsing a  TreeModel structure" New topic

Parsing a TreeModel structure

Trevor Price

Joined: May 19, 2006
Posts: 16
Say I have a very large tree structure (7000+ nodes) and I need to parse it. What's the fastest way to accomplish this? I've been toying with the code below, but it's just too slow.

Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

I'm going to assume that "fastest" refers to how fast you can get the code written:I'm just guessing at what "parse" means in this context, by the way. I'm guessing it means you want to list out all of the nodes in some order. There are several other enumerations you can choose from if you don't like post order.
Trevor Price

Joined: May 19, 2006
Posts: 16
Sorry, should have been more clear. By "fast", I mean "optimized", i.e., parsing 7000 nodes is hitting my server hard for about 6 seconds. Ultimately, I'm going to need to be able to manipulate the data in multiple ways. Maybe Enumeration isn't the most optimized code for this.

For example:

Jaap Vermeer

Joined: Apr 04, 2006
Posts: 16
Well... Paul Clapham's code is definitely the way to go if you want any sort of maintainability. Then to make it faster, you'll have to profile the code and see what it is doing in thos 6 seconds.
Although 1000 iterations a second does not sound absurd, you might be able to make it faster.

The direction you are going, given your example, sounds bad. The order in which the nodes are processed will (likely) not have a major effect on performance, you still need to go through 7000 nodes.
I agree. Here's the link:
subject: Parsing a TreeModel structure
jQuery in Action, 3rd edition