I just wanted to share something I just realized...

Today I've been looking at the Functors API in commons-collections to  
see how that is applicable to the Traverser API in Neo. The one thing  
I was missing in the Traverser API was Transformer. There are two  
Predicate-like interfaces in the StopEvaluator and ReturnEvaluator but  
I miss something like the Transformer interface. As I was playing  
around with this I realized (as maybe many of you have done) that  
there indeed is something Transformer-like in Neo, namely  
IterableWrapper (in neo-utils). Up until now I've only used this for  
things like this:

public Iterable<Receiver> getRecieversOfDonations() {
                Traverser traverser = ... //My traverser that returns 
RecieverNodes

                return new IterableWrapper<Receiver, Node>(traverser) {
                        @Override
                        protected Receiver underlyingObjectToObject(Node 
object) {
                                return new ReceiverNode(object);
                        }
                };
        }

What I realized today is that this is more powerful than that, and  
that I can do whatever I want with it, for example:

Iterable<SomeBean> iterable = new IterableWrapper<SomeBean,  
Node>(traverser){
        @Override
        protected SomeBean underlyingObjectToObject(Node node) {
                CreditNode creditNode = new CreditNode(node);
                DateTime createdDateTime = creditNode.getCreatedDateTime();
                Relationship someRelationship = creditNode
                                .getSingleRelationship(...);
                CreditNode someOtherCredit = new CreditNode(someRelationship
                                .getStartNode());
                AnotherNode anotherNode = new  
AnotherNode(someOtherCredit.traverse(...)
                                .iterator().next());
                return new SomeBean(
                                createdDateTime, 
someOtherCredit.getSomething(),  
anotherNode.getName(), creditNode.getSomething());
        }
};

When used like this the name may be somewhat inaccurate  
(IterableTransformer?), but I think this is really powerful. What do  
you think?

Best regards, Mattias Ask
-------------------------------------------
Jayway AB, +46 701 469284
www.jayway.com

Jayway is the founder of Öredev and Qi4J
www.oredev.org
www.qi4j.org




_______________________________________________
Neo mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to