You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by Marcel Reutegger <mr...@adobe.com> on 2012/09/12 11:29:46 UTC

ChildNodeEntry

Hi,

I was wondering why we have the interface ChildNodeEntry?
To me it looks like its usages can be replaced with other methods
on NodeState. e.g. the following code in JsopDiff.toJson(NodeState, JsopBuilder):

        for (ChildNodeEntry child : nodeState.getChildNodeEntries()) {
            jsop.key(child.getName());
            toJson(child.getNodeState(), jsop);
        }

can simply be replaced with:

        for (String childName : nodeState.getChildNodeNames()) {
            jsop.key(childName);
            toJson(nodeState.getChildNode(childName), jsop);
        }

regards
 marcel

Re: ChildNodeEntry

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Wed, Sep 12, 2012 at 11:43 AM, Marcel Reutegger <mr...@adobe.com> wrote:
> I guess this is due to NodeState not knowing its name, but
> on the other hand separating the name from the child
> NodeState allows for enumerating the names only without
> the need to actually load the states...

Rigth. There are also the nice design aspects of not making a special
case of the root node or having to worry about ensuring consistency
constraints like name.equals(node.getChildNode(name).getName()).

BR,

Jukka Zitting

RE: ChildNodeEntry

Posted by Marcel Reutegger <mr...@adobe.com>.
I see, that makes sense. Thanks for the clarification. I'll
add that to the JavaDoc.

I guess this is due to NodeState not knowing its name, but
on the other hand separating the name from the child
NodeState allows for enumerating the names only without
the need to actually load the states...

regards
 marcel

> -----Original Message-----
> From: Jukka Zitting [mailto:jukka.zitting@gmail.com]
> Sent: Mittwoch, 12. September 2012 11:35
> To: oak-dev@jackrabbit.apache.org
> Subject: Re: ChildNodeEntry
> 
> Hi,
> 
> On Wed, Sep 12, 2012 at 11:29 AM, Marcel Reutegger
> <mr...@adobe.com> wrote:
> > I was wondering why we have the interface ChildNodeEntry?
> 
> It allows you to avoid extra name lookups when traversing over all
> children of a node.
> 
> For example, if on a large node the cost of iterating over all child
> nodes is O(n) and that of looking up a specific child is O(log n),
> then with the cost difference between the alternatives you outlined is
> O(n) versus O(n log n).
> 
> BR,
> 
> Jukka Zitting

Re: ChildNodeEntry

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Wed, Sep 12, 2012 at 11:29 AM, Marcel Reutegger <mr...@adobe.com> wrote:
> I was wondering why we have the interface ChildNodeEntry?

It allows you to avoid extra name lookups when traversing over all
children of a node.

For example, if on a large node the cost of iterating over all child
nodes is O(n) and that of looking up a specific child is O(log n),
then with the cost difference between the alternatives you outlined is
O(n) versus O(n log n).

BR,

Jukka Zitting