On 10/16/2012 10:24 AM, Rainer Klute wrote:
Hi Johannes,
I had a quick glance at Sirix: looks quite good overall and covers nicely navigational requirements.
Thanks.
Okay, I don't like ugly interface names starting with a capital I, like IFooBar. I'd prefer working with interfaces named FooBar and having implementing classes like FooBarImpl or FooBarWhatever. The reason is that I see the interface names all the time, so they must be nice, easy, pronouncable words. The names of the implementing classes I have to see seldom or not at all, so they may be ugly.
Thanks for having a quick look, I think I'll really change the interface names (and possibly or most probably also enums and method parameters). Does someone maybe know how to quickly rename _all_ parameters from pFooBar to fooBar in Eclipse (that is strip the "p" and change from upper to lowercase letters)?
After all the interfaces are most of the times either in the API-package or in dedicated interface-packages.
Using a fluent API can be very nice like in
wtx.moveTo(15).get().moveToRightSibling().get().moveToFirstChild().get().insertCommentAsFirstChild("foo");
That is one of the things I wasn't sure about. But now I'm quiet happy because you have the freedom to either do
moveTo(15).get() to get the transaction handle _or_ moveTo(15).hasMoved() in expressions which must return a boolean to check if the transaction-cursor really moved (for instance it doesn't move if the node with the given node-key is not available). But you never get a NPE.
However, a fluent expression is not necessarily easy to understand. Example:
for (final IAxis axis = new DescendantAxis.Builder(wtx).includeSelf().visitor( Optional.<IVisitor> of(new ModificationVisitor(wtx, wtx.getNode() .getNodeKey()))).build(); axis.hasNext();) { axis.next(); }
I cannot grasp immediately what is going on here by reading the expression from left to right. But, well, that may be due to not being content with your API.
Ok, that's quiet hard, I have to admit. But maybe that's one of the most powerful axis I've implemented.
For instance it's very closely modeled after the new Java7 file system walker API and works in conjunction with an IVisitResult interface or more precisely the enum:
/** * The result type of an {@link IVisitor} implementation. * * @author Johannes Lichtenberger, University of Konstanz */ public enum EVisitResult { /** Continue without visiting the siblings of this structural node. */ SKIPSIBLINGS,
/** Continue without visiting the descendants of this element. */ SKIPSUBTREE,
/** Continue traversal. */ CONTINUE,
/** Terminate traversal. */ TERMINATE, }
described afterwards. Thus, you are able to guide the preorder traversal (for instance skip siblings of the currently selected node, skip a whole subtree, continue normally in preorder or terminate the traversal).
It's a variant which you maybe should really use with a visitor implementation, that is an implementation which does different things for different node kinds:
/** * My visitor doing something application specific with different node kinds. */ public final class MyVisitor extends AbsVisitorSupport { @Override public IVisitResult visit(final @Nonnull ImmutableElement pNode) { return processElementNode(pNode); }
@Override public IVisitResult visit(final @Nonnull ImmutableText pNode) { return processTextNode(pNode); }
... }
A rather simpler invokation might be to use the "normal" DescendantAxis:
for (final IAxis axis = new DescendantAxis(trx); axis.hasNext();) { axis.next();
if (trx.isElement()) { LOGGER.info(trx.getName());
// Do something. } }
Or if you have to iterate over all structural and non-structural nodes use new NonStructuralWrapperAxis(new DescendantAxis(trx)) (I'm not sure about the name "NonStructuralWrapperAxis" I added a few days ago).
You are free to use hasNext(), next() and peek() for every axis, which might be very powerful sometimes.
Even implementing axis (if you have to do so at some day (now) is very _very_ easy). For instance just implement "nextKey()" and call "done()" once done.
I'd say it's easily one of the best use case you have ;-)
Furthermore a few weeks ago I've changed all filtering classes (namely just one, AbsFilter), such that all filters are now (Google) Guava Predicates. In my opinion very nice.
I wish you all the best with Sirix!
Thanks, but at times it's just depressing having spend endless hours without as of now anyone having ever used the project (despite myself and other students which have worked with (and on) Treetank -- a system which Sirix is based on or a fork which specializes on the tree-structure) ;-) For instance it's _very_ helpful to get comments like rename the interface-names and so on. That's the first thing I will do now...
BTW: If you are still interested you can also discuss or ask for help in https://groups.google.com/forum/#!forum/sirix-users, would be great.
kind regards, Johannes