jackrabbit-oak-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tobias Bocanegra <tri...@apache.org>
Subject Tree.hasChild() / Tree.getChild()
Date Mon, 30 Sep 2013 20:22:49 GMT
Hi,

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. Currently the
hasChild() is implemented with getChild() anyways:

    public boolean hasChild(String name) {
        return createChild(checkNotNull(name)).exists();
    }

so I think that it could make sense to add an optimizable convenience method:

    /**
     * Get a possibly non existing child of this {@code Tree}. If the
child does not exist and
     * {@code mustExist} is true, null is returned.
     * <p>
     * This is basically an optimized convenience method for
     *
     * <pre>
     * child = tree.getChild(name); return !mustExist ||
child.exists() ? child : null;
     * </pre>
     *
     * @param name The name of the child to retrieve.
     * @param mustExist Flag enforcing existence
     * @return The child with the given {@code name} or null if the
chid does not exist
     *              and {@code mustExist} is true.
     */
    @Nullable
    Tree Tree.getChild(@Nonnull String name, boolean mustExist)

WDYT?
Regards, Toby

Mime
View raw message