TreeModelAbstract>>withAllParents: question

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

TreeModelAbstract>>withAllParents: question

Mikael Svane
I have discovered what I think is a somewhat illogical behaviour of
TreeModel (or actually TreeModelAbstract). I am not sure if it is a bug, but
it isn't quite what I had expected. Try this:

t := TreeModel new.
t add: 1 asChildOf: nil;
    add: 2 asChildOf: 1;
    add: 3 asChildOf: 2;
    add: 4 asChildOf: 3.

"Display this:"
t withAllParents: 4

This answers an OrderedCollection(4 1 2 3), when I had expected an
OrderedCollection(1 2 3 4). If this is a bug, then I suggest changing
TreeModelAbstract>>withAllParents: to this:

withAllParents: anObject
 "Answer an OrderedCollection of anObject and all of its parents"

 | parents |
 parents := OrderedCollection new: 64.
 parents addAll: (self allParentsOf: anObject).
 parents add: anObject.
 ^parents


Best regards,

Mikael
[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: TreeModelAbstract>>withAllParents: question

Blair McGlashan
Mikael

You wrote in message news:9b6bt6$7s8pd$[hidden email]...
> I have discovered what I think is a somewhat illogical behaviour of
> TreeModel (or actually TreeModelAbstract). I am not sure if it is a bug,
but

> it isn't quite what I had expected. Try this:
>
> t := TreeModel new.
> t add: 1 asChildOf: nil;
>     add: 2 asChildOf: 1;
>     add: 3 asChildOf: 2;
>     add: 4 asChildOf: 3.
>
> "Display this:"
> t withAllParents: 4
>
> This answers an OrderedCollection(4 1 2 3), when I had expected an
> OrderedCollection(1 2 3 4).

I don't think #withAllParents: is necessarily supposed to be making any
promises about the order in which the nodes are returned, but as it is
answering an OrderedCollection (and says so in the comment) I think it would
be most sensible if it answered the reverse path to the root, so I will make
an entry in the bugs system to have it altered to do that.

Regards

Blair