Hi,

This might seem a minor point but...

The method Node.getRelationships() returns Iterable<Relationships>,
implemented by IntArrayIterator. It turns out that IntArrayIterator
implements both Iterable and Iterator, its iterator() method returning
itself.

My understanding was that an Iterable was supposed to be stateless, whereas
an Iterator is obviously stateful. Having a stateless Iterable makes it
useable multiple times in a foreach loop, as it returns a new Iterator
whenever iterator() is called. See for instance
http://stackoverflow.com/questions/839178/why-is-javas-iterator-not-an-iterable

Unfortunately, IntArrayIterator is a stateful Iterable.

I've noticed that Traverser, which extends Iterable, is implemented by
TraverserImpl, which does not implement Iterator, but returns a new
TraverserIterator whenever iterator() is called. This seems right to me.

I actually ran into this stateless/stateful issue when I refactored a piece
of code that was using the traversal framework and now uses getRelationships
instead. Some of the tests failed because they were reusing a resulting
Iterable.

Is the design of IntArrayIterator intentional? Or is it an oversight?

Thanks,
Pierre
_______________________________________________
Neo4j mailing list
[email protected]
https://lists.neo4j.org/mailman/listinfo/user

Reply via email to