Created
March 8, 2010 16:50
-
-
Save rrichardson/325339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait NeoIterable[T] extends Iterator[T] { | |
def first() : T = { | |
this.take(1).toList.head | |
} | |
} | |
implicit def jiterable2iterable[T](it: java.lang.Iterable[T]) = new Wrapper[T](it.iterator()) with NeoIterable[T] | |
use: | |
class RichNode(node: Node) { | |
object getOtherNodes { | |
def apply() : Iterable[Node] = getNodesFromRels(node.getRelationships()) | |
def apply(dir : Direction) : Iterable[Node] = getNodesFromRels(node.getRelationships(dir)) | |
def apply(rel : RelationshipType, dir : Direction) : Iterable[Node] = getNodesFromRels(node.getRelationships(rel, dir)) | |
def apply(rel : RelationshipType) : Iterable[Node] = getNodesFromRels(node.getRelationships(rel)) | |
private def getNodesFromRels(rels : Iterable[Relationship]) : Iterable[Node] = rels.map { r => | |
r.getOtherNode(node) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment