velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Simon Christian <>
Subject Re: my tree
Date Tue, 17 Jul 2001 14:54:02 GMT

Uday Kumar wrote:
> hi Tim
> i did write a code to print out a tree, but i am sure no one wud want to see
> that, as it is such a lousy code. wrote it just to serve the purpose,
> debugging it wud be a pain for new-comers. my problem is... i have a
> vectorof objects and they are arranged in order. i have to print them out
> one by one, but with the only condition that some of them might have
> subcategories, i can call some methods on it(ex. hasSubCategories( ) ) and
> then according to the result, i print out with indentations. as i cud not do
> the indentations, i made tables and each time i changed the width and
> printed it out...
> lemme give an example. actually, the categories would be like---
> main1
>    test1
>    test2
>       test22
>       test23
>   test3
> main2
> if this was my tree, the vector i have to recurse thru would be
> [main1,test1,test2,test22,test23,test3,main2]. all the things are in order,
> ready to be printed straightaway, but i have to identify whether each of
> them has subcategories and then print it as above.
> now, i made u my problem more clear, tell me if this works in the SAME WAY u
> did? if that is the case, i wud replace my code with yours. please let me
> know

Is it possible for the objects in your vector to report how many nodes
there are in the tree between themselves and the 'root'? If so this is
the easy way to tackle your problem. e.g. from your example, test22
would have 2 nodes above it, hence indent it with two units. The
simplest unit to use might be a non-breaking-space. Example vm code:

#foreach( $node in $myVector )
#foreach( $i in $node.countParentNodes() )&nbsp;&nbsp;&nbsp;#end

Given it's a brute force approach, but it would work ok (or am i missing

- simon

View raw message