jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Dürig <mdue...@apache.org>
Subject Re: Tree.hasChild() / Tree.getChild()
Date Tue, 01 Oct 2013 07:45:10 GMT


On 1.10.13 3:56 , Jukka Zitting wrote:
> On Mon, Sep 30, 2013 at 4:22 PM, Tobias Bocanegra<tripod@apache.org>  wrote:
>> >I was looking at some spots where the code can be optimized, and I
>> >found some occurrences where a Tree.hasChild() is followed by a
>> >Tree.getChild(). I think this pattern is used commonly.
> Right. I think the pattern dates back to the time before we added the
> Tree.exists() method and made Tree.getChild() return non-null every
> time regardless of whether the identified child exists or is
> accessible.
>
> Instead of the old pattern ...
>
>      if (tree.hasChild(name)) {
>          Tree child = tree.getChild(name);
>          ...;
>      } else {
>          ...;
>      }
>
> ... a better pattern would now be ...
>
>      Tree child = tree.getChild(name);
>      if (child.exists()) {
>          ...;
>      } else {
>          ...;
>      }
>

We could remove the hasChild() method to enforce this pattern. As you 
say this is a leftover from the time we didn't have the exists() method. 
WDYT?

Michael

Mime
View raw message