Re: Walking an Object's Relationships
Re: Walking an Object's Relationships
- Subject: Re: Walking an Object's Relationships
- From: Florijan Stamenkovic <email@hidden>
- Date: Tue, 23 Aug 2005 17:48:17 +0200
On Aug 22, 2005, at 21:12, email@hidden wrote:
I am trying to create a virtual tree based on the relationships (not
inheritance) of objects in an array and not sure how to go about
doing it.
I am looking into using a tree set as a possible solution.
You refer to Java Collection's TreeSet? All that the TreeSet does is
implement a Set interface (so, no duplicates in the collection), and
keeps them sorted depending on the comparator you feed to the TreeSet
(see API). And as I understand, you want to have a tree structure (as
in file-system's tree organization?), which the TreeSet has nothing to
do with. Just one more fine example of Java class naming...
If you could be more specific, maybe somebody could help you more
easily. What do you want to do? Display? Scan? Relate? Organize? Sum?
...
Tip: if you have a tree with non defined max depth, you are looking for
a recursive function...
Simple example:
public int countOfSubtree(MyEO eo)
{
int count;
NSArray objects = eo.relationship();
for(int i = 0 ; i < objects.count ; i++)
count += countOfSubtree( (MyEO)objects.objectAtIndex(i) );
//recursion
return count;
}
Cheers
Flor
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden