diff --git a/core/src/main/scala/flatgraph/Graph.scala b/core/src/main/scala/flatgraph/Graph.scala index 49119601..d499224d 100644 --- a/core/src/main/scala/flatgraph/Graph.scala +++ b/core/src/main/scala/flatgraph/Graph.scala @@ -157,4 +157,15 @@ class Graph(val schema: Schema, val storagePathMaybe: Option[Path] = None) exten } } + override def toString(): String = + s"Graph[${nodeCount()} nodes]" + + def nodeCountByLabel: Map[String, Int] = { + schema.nodeKinds + .map(schema.getNodeLabel) + .map(label => label -> nodeCount(label)) + .filter { case (label, count) => count > 0 } + .toMap + } + } diff --git a/core/src/test/scala/flatgraph/GraphTests.scala b/core/src/test/scala/flatgraph/GraphTests.scala index 8f726843..cfe216f8 100644 --- a/core/src/test/scala/flatgraph/GraphTests.scala +++ b/core/src/test/scala/flatgraph/GraphTests.scala @@ -173,6 +173,9 @@ class GraphTests extends AnyWordSpec with Matchers { Accessors.getNeighborsIn(V0_0_GNode).size shouldBe 2 V0_0_GNode.out.size shouldBe 1 V0_0_GNode.in.size shouldBe 2 + + g.toString shouldBe "Graph[4 nodes]" + g.nodeCountByLabel shouldBe Map("V0" -> 2, "V1" -> 2) } val schema = TestSchema.make(1, 1) diff --git a/domain-classes-generator/src/main/scala/flatgraph/codegen/DomainClassesGenerator.scala b/domain-classes-generator/src/main/scala/flatgraph/codegen/DomainClassesGenerator.scala index fcbbe7ef..b56595ce 100644 --- a/domain-classes-generator/src/main/scala/flatgraph/codegen/DomainClassesGenerator.scala +++ b/domain-classes-generator/src/main/scala/flatgraph/codegen/DomainClassesGenerator.scala @@ -890,6 +890,9 @@ class DomainClassesGenerator(schema: Schema) { | | override def close(): Unit = | _graph.close() + | + | override def toString(): String = + | String.format("$domainShortName[%s]", graph) |} | |@flatgraph.help.TraversalSource