Skip to content

Commit

Permalink
add nodestarters by nodeId (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrehm authored Jul 3, 2024
1 parent ab07c3a commit 51e505f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/scala/flatgraph/Graph.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class Graph(val schema: Schema, val storagePathMaybe: Option[Path] = None) exten
def node(id: Long): GNode =
node(GNode.extractKind(id), GNode.extractSeq(id))

/** Lookup node by kind and seq - note: this may return null or throw an exception if the referenced node doesn't exist */
/** Lookup node by kind and seq - note: this may return null if the referenced node doesn't exist */
def node(kind: Int, seq: Int): GNode = {
if (kind < 0 || kind >= nodesArray.length || seq < 0 || seq >= nodesArray(kind).length) return null
val node = nodesArray(kind)(seq)
if (node._isDeleted) null
else node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,10 @@ class DomainClassesGenerator(schema: Schema) {
|
| @flatgraph.help.Doc(info = "all nodes")
| def all: Iterator[nodes.StoredNode] = wrapped$domainShortName.graph.allNodes.asInstanceOf[Iterator[nodes.StoredNode]]
|
| def id(nodeId: Long):Iterator[nodes.StoredNode] = Option(wrapped$domainShortName.graph.node(nodeId)).iterator.asInstanceOf[Iterator[nodes.StoredNode]]
|
| def ids(nodeIds: Long*):Iterator[nodes.StoredNode] = nodeIds.iterator.flatMap(id)
|
|${starters.mkString("\n\n")}
|}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class GenericDomainNodeStarters(val wrappedGenericDomain: GenericDomain) {
@flatgraph.help.Doc(info = "all nodes")
def all: Iterator[nodes.StoredNode] = wrappedGenericDomain.graph.allNodes.asInstanceOf[Iterator[nodes.StoredNode]]

def id(nodeId: Long): Iterator[nodes.StoredNode] =
Option(wrappedGenericDomain.graph.node(nodeId)).iterator.asInstanceOf[Iterator[nodes.StoredNode]]

def ids(nodeIds: Long*): Iterator[nodes.StoredNode] = nodeIds.iterator.flatMap(id)

/** */
@flatgraph.help.Doc(info = """""")
def nodeA: Iterator[nodes.NodeA] = wrappedGenericDomain.graph._nodes(0).asInstanceOf[Iterator[nodes.NodeA]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class GratefulDeadNodeStarters(val wrappedGratefulDead: GratefulDead) {
@flatgraph.help.Doc(info = "all nodes")
def all: Iterator[nodes.StoredNode] = wrappedGratefulDead.graph.allNodes.asInstanceOf[Iterator[nodes.StoredNode]]

def id(nodeId: Long): Iterator[nodes.StoredNode] =
Option(wrappedGratefulDead.graph.node(nodeId)).iterator.asInstanceOf[Iterator[nodes.StoredNode]]

def ids(nodeIds: Long*): Iterator[nodes.StoredNode] = nodeIds.iterator.flatMap(id)

/** */
@flatgraph.help.Doc(info = """""")
def artist: Iterator[nodes.Artist] = wrappedGratefulDead.graph._nodes(0).asInstanceOf[Iterator[nodes.Artist]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class HierarchicalNodeStarters(val wrappedHierarchical: Hierarchical) {
@flatgraph.help.Doc(info = "all nodes")
def all: Iterator[nodes.StoredNode] = wrappedHierarchical.graph.allNodes.asInstanceOf[Iterator[nodes.StoredNode]]

def id(nodeId: Long): Iterator[nodes.StoredNode] =
Option(wrappedHierarchical.graph.node(nodeId)).iterator.asInstanceOf[Iterator[nodes.StoredNode]]

def ids(nodeIds: Long*): Iterator[nodes.StoredNode] = nodeIds.iterator.flatMap(id)

/** */
@flatgraph.help.Doc(info = """""")
def nodeX: Iterator[nodes.NodeX] = wrappedHierarchical.graph._nodes(0).asInstanceOf[Iterator[nodes.NodeX]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class GratefulDeadTests extends AnyWordSpec {
gratefulDead.artist.name.sorted shouldBe List("Bo_Diddley", "Garcia")
gratefulDead.artist.name("Garcia").sang.name.l shouldBe List("HEY BO DIDDLEY")
gratefulDead.song.writtenBy.name.l shouldBe List("Bo_Diddley")
gratefulDead.ids(0L, 1L << 32).l shouldBe List(boDiddley.storedRef.get, heyBoDiddley.storedRef.get)
gratefulDead.id(2L).l shouldBe List.empty
}

lazy val gratefulDead = {
Expand Down

0 comments on commit 51e505f

Please sign in to comment.