Having lots of fun experimenting with Neo. Nice job.

Its not clear from the traverser documentation what behaviour I should
expect from a traverser if both stop evaluator and returnable evaluator
return true. Should it be returned or not? My random testing suggests that
it is and you can reuse the same logic for a StopEvaluator and a
ReturnableEvaluator if you need a single result, like this code for a
subsumption test on a tree:

private boolean inPackage(Node n, String name) {
                Object[] rels = {
                        AbstractModelManager.Relationship.IS_COMPONENT,
Direction.OUTGOING,
                        AbstractModelManager.Relationship.IS_SUBPACKAGE,
Direction.OUTGOING,
                };
                Hashtable<String, String> criteria = new Hashtable<String,
String>();
                criteria.put("name", name);
                criteria.put("type", "package");
                MixedEvaluator me =
nodesWithPropertiesCaseInsensitive(criteria);
                Traverser t = n.traverse(Order.BREADTH_FIRST, me, me, rels);
                if (t.iterator().hasNext()) {
                    log.info("package found!:" +name);
                    return true;
                } else {
                    return false;
                }
            }


public MixedEvaluator nodesWithPropertiesCaseInsensitive(final
Hashtable<String,String> tests) {
        return new MixedEvaluator() {
            public boolean isReturnableNode(TraversalPosition currentPos) {
                boolean aggregate = true;
                for (Entry<String, String> test: tests.entrySet()) {
                    try {
                        if
(!currentPos.currentNode().getProperty(test.getKey()).toString().equalsIgnoreCase(test.getValue().toString()))
aggregate = false;
                    } catch (NotFoundException e) {
                        aggregate = false;
                    }
                }
                return aggregate;
            }
            public boolean isStopNode(TraversalPosition currentPos) {
                return isReturnableNode(currentPos);
            }
        };
    }


where a MixedEvaluator is simply:

public interface MixedEvaluator extends ReturnableEvaluator, StopEvaluator {

}


Is there an abstract parent of Returnable and Stop evaluators that could be
better used here?

Cheers,

Rob.
_______________________________________________
Neo mailing list
User@lists.neo4j.org
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to