public final class TopologicalIndex extends java.lang.Object implements KnowledgeIndex
This kind of reverse topological ordering is useful for languages
like C++ that need to define shapes before they can be referenced.
Only non-recursive shapes are reverse-topologically ordered using
getOrderedShapes()
. However, recursive shapes are queryable
through getRecursiveShapes()
. When this returned Set
is
iterated, recursive shapes are ordered by their degree of recursion (the
number of edges across all recursive closures), and then by shape ID
when multiple shapes have the same degree of recursion.
The recursion closures of a shape can be queried using
getRecursiveClosure(ToShapeId)
. This method returns a list of
paths from the shape back to itself. This list can be useful for code
generation to generate different code based on if a recursive path
passes through particular types of shapes.
Constructor and Description |
---|
TopologicalIndex(Model model) |
Modifier and Type | Method and Description |
---|---|
java.util.Set<Shape> |
getOrderedShapes()
Gets all reverse-topologically ordered shapes, including members.
|
java.util.Set<PathFinder.Path> |
getRecursiveClosure(ToShapeId shape)
Gets the recursive closure of a given shape represented as
PathFinder.Path objects. |
java.util.Set<Shape> |
getRecursiveShapes()
Gets all shapes that have edges that are part of a recursive closure,
including container shapes (list/set/map/structure/union) and members.
|
boolean |
isRecursive(ToShapeId shape)
Checks if the given shape has edges with recursive references.
|
static TopologicalIndex |
of(Model model)
Creates a new
TopologicalIndex . |
public TopologicalIndex(Model model)
public static TopologicalIndex of(Model model)
TopologicalIndex
.model
- Model to create the index from.TopologicalIndex
.public java.util.Set<Shape> getOrderedShapes()
When the returned Set
is iterated, shapes are returned in
reverse-topological. Note that the returned set does not contain
recursive shapes.
Set
.public java.util.Set<Shape> getRecursiveShapes()
When iterated, the returned Set
is ordered from fewest number
of edges to the most number of edges in the recursive closures, and then
alphabetically by shape ID when there are multiple entries with
the same number of edges.
public boolean isRecursive(ToShapeId shape)
shape
- Shape to check.public java.util.Set<PathFinder.Path> getRecursiveClosure(ToShapeId shape)
PathFinder.Path
objects.
The first element of each path is the given shape
,
and the last element of each path is the first shape that is
encountered a second time in the path (i.e., the point of
recursion).
shape
- Shape to get the recursive closures of.Set
if the shape is not recursive.