Interface GraphStructure<G,N,C,P>

Type Parameters:
G - the type of the (root node of a) graph
N - the type of nodes
C - the type of node classes
P - the type of node ports

public interface GraphStructure<G,N,C,P>
Interface that defines structure of a compiler graph. The structure of a graph is composed from nodes with properties, the classes of individual nodes, and ports associated with each node that may contain edges to other nodes. The structure of a graph is assumed to be immutable for the time of operations on it.
  • Method Details

    • graph

      G graph(G currentGraph, Object obj)
      Casts obj to graph, if possible. If the given object obj can be seen as a graph or sub-graph of a graph, then return the properly typed instance. Otherwise return null
      Parameters:
      currentGraph - the currently processed graph
      obj - an object to check and view as a graph
      Returns:
      appropriate graph object or null if the object doesn't represent a graph
    • nodes

      Iterable<? extends N> nodes(G graph)
      Nodes of a graph. Each graph is composed from a fixed set of nodes. This method returns an iterable which provides access to all of them - the number of nodes provided by the iterable must match the number returned by nodesCount(java.lang.Object) method.
      Parameters:
      graph - the graph to query for nodes
      Returns:
      iterable with all the graph's nodes
      See Also:
    • nodesCount

      int nodesCount(G graph)
      Number of nodes in a graph. The number must match the content returned by nodes(java.lang.Object) method.
      Parameters:
      graph - the graph to query
      Returns:
      the number of nodes that will be returned by nodes(java.lang.Object)
    • nodeId

      int nodeId(N node)
      Id of node. Each node in the graph is uniquely identified by an integer value. If two nodes have the same id, then they shall be == to each other.
      Parameters:
      node - the node to query for an id
      Returns:
      the id of the node
    • nodeHasPredecessor

      boolean nodeHasPredecessor(N node)
      Checks if there is a predecessor for a node.
      Parameters:
      node - the node to check
      Returns:
      true if it has a predecessor, false otherwise
    • nodeProperties

      void nodeProperties(G graph, N node, Map<String,? super Object> properties)
      Collects node properties. Each node can be associated with additional properties identified by their name. This method shall copy them into the provided map.
      Parameters:
      graph - the current graph
      node - the node to collect properties for
      properties - the map to put the properties to
    • node

      N node(Object obj)
      Finds a node for obj, if possible. If the given object obj can be seen as an instance of node return the properly typed instance of the node class. Otherwise return null.
      Parameters:
      obj - an object to find node for
      Returns:
      appropriate graph object or null if the object doesn't represent a node
    • nodeClass

      C nodeClass(Object obj)
      Finds a node class for obj, if possible. If the given object obj can be seen as an instance of node class return the properly typed instance of the node class. Otherwise return null.
      Parameters:
      obj - an object to find node class for
      Returns:
      appropriate graph object or null if the object doesn't represent a node class
    • classForNode

      C classForNode(N node)
      Finds a node class for node.
      Parameters:
      node - an instance of node in this graph
      Returns:
      the node's node class, never null
    • nameTemplate

      String nameTemplate(C nodeClass)
      The template used to build the name of nodes of this class. The template may use references to inputs ({i#inputName}) and its properties ({p#propertyName}).
      Parameters:
      nodeClass - the node class to find name template for
      Returns:
      the string representing the template
    • nodeClassType

      Object nodeClassType(C nodeClass)
      Java class for a node class.
      Parameters:
      nodeClass - the node class
      Returns:
      the Class or other type representation of the node class
    • portInputs

      P portInputs(C nodeClass)
      Input ports of a node class. Each node class has a fixed set of ports where individual edges can attach to.
      Parameters:
      nodeClass - the node class
      Returns:
      input ports for the node class
    • portOutputs

      P portOutputs(C nodeClass)
      Output ports of a node class. Each node class has a fixed set of ports from where individual edges can point to other nodes.
      Parameters:
      nodeClass - the node class
      Returns:
      output ports for the node class
    • portSize

      int portSize(P port)
      The number of edges in a port. The protocol will then call methods edgeDirect(java.lang.Object, int), edgeName(java.lang.Object, int), edgeType(java.lang.Object, int) and edgeNodes(java.lang.Object, java.lang.Object, java.lang.Object, int) for indexes from 0 to portSize - 1
      Parameters:
      port - the port
      Returns:
      number of edges in this port
    • edgeDirect

      boolean edgeDirect(P port, int index)
      Checks whether an edge is direct. Direct edge shall have exactly one node - it is an error to return more than one for such an edge from the method.
      Parameters:
      port - the port
      index - index from 0 to portSize(java.lang.Object) minus 1
      Returns:
      true if only one node can be returned from edgeNodes(java.lang.Object, java.lang.Object, java.lang.Object, int) method
    • edgeName

      String edgeName(P port, int index)
      The name of an edge.
      Parameters:
      port - the port
      index - index from 0 to portSize(java.lang.Object) minus 1
      Returns:
      the name of the edge
    • edgeType

      Object edgeType(P port, int index)
      Type of an edge. The type must be a graph enum - e.g. either real instance of Enum subclass, or something that the GraphOutput.Builder can recognize as enum.
      Parameters:
      port -
      index - index from 0 to portSize(java.lang.Object) minus 1
      Returns:
      any Enum representing type of the edge
    • edgeNodes

      Collection<? extends N> edgeNodes(G graph, N node, P port, int index)
      Nodes where the edges for a port lead to/from. This method is called for both direct/non-direct edges. In case of a direct edge the returned collection must have exactly one element.
      Parameters:
      graph - the graph
      node - the node in the graph
      port - port of the node class
      index - index from 0 to portSize(java.lang.Object) minus 1
      Returns:
      null if there are no edges associated with given port or collection of nodes where to/from the edges lead to