Class InMemoryStateFlowGraph

    • Field Detail

      • LOG

        private static final org.slf4j.Logger LOG
      • readLock

        private final Lock readLock
      • writeLock

        private final Lock writeLock
      • stateCounter

        private final AtomicInteger stateCounter
        Intermediate counter for the number of states, not relaying on getAllStates.size() because of Thread-safety.
      • nextStateNameCounter

        private final AtomicInteger nextStateNameCounter
    • Constructor Detail

      • InMemoryStateFlowGraph

        @Inject
        public InMemoryStateFlowGraph​(ExitNotifier exitNotifier,
                                      StateVertexFactory vertexFactory)
        The constructor.
        Parameters:
        exitNotifier - used for triggering an exit.
    • Method Detail

      • putIfAbsent

        public StateVertex putIfAbsent​(StateVertex stateVertex)
        Adds a state (as a vertex) to the State-Flow Graph if not already present. More formally, adds the specified vertex, v, to this graph if this graph contains no vertex u such that u.equals(v). If this graph already contains such vertex, the call leaves this graph unchanged and returns false. In combination with the restriction on constructors, this ensures that graphs never contain duplicate vertices. Throws java.lang.NullPointerException - if the specified vertex is null. This method automatically updates the state name to reflect the internal state counter.
        Parameters:
        stateVertex - the state to be added.
        Returns:
        the clone if one is detected null otherwise.
        See Also:
        Graph.addVertex(Object)
      • putIfAbsent

        private StateVertex putIfAbsent​(StateVertex stateVertex,
                                        boolean correctName)
        Adds a state (as a vertex) to the State-Flow Graph if not already present. More formally, adds the specified vertex, v, to this graph if this graph contains no vertex u such that u.equals(v). If this graph already contains such vertex, the call leaves this graph unchanged and returns false. In combination with the restriction on constructors, this ensures that graphs never contain duplicate vertices. Throws java.lang.NullPointerException - if the specified vertex is null.
        Parameters:
        stateVertex - the state to be added.
        correctName - if true the name of the state will be corrected according to the internal state counter.
        Returns:
        the clone if one is detected null otherwise.
        See Also:
        Graph.addVertex(Object)
      • setNearDuplicate

        private void setNearDuplicate​(StateVertex vertex)
      • hasClone

        public boolean hasClone​(StateVertex vertex)
        Adding assignment to dynamic fragments in case the vertex is hybridstate vertex
        Specified by:
        hasClone in interface StateFlowGraph
      • getById

        public StateVertex getById​(int id)
        Specified by:
        getById in interface StateFlowGraph
        Parameters:
        id - The ID of the state
        Returns:
        The state if found or null.
      • addEdge

        public boolean addEdge​(StateVertex sourceVertex,
                               StateVertex targetVertex,
                               Eventable clickable)
        Adds the specified edge to this graph, going from the source vertex to the target vertex. More formally, adds the specified edge, e, to this graph if this graph contains no edge e2 such that e2.equals(e). If this graph already contains such an edge, the call leaves this graph unchanged and returns false. Some graphs do not allow edge-multiplicity. In such cases, if the graph already contains an edge from the specified source to the specified target, than this method does not change the graph and returns false. If the edge was added to the graph, returns true. The source and target vertices must already be contained in this graph. If they are not found in graph IllegalArgumentException is thrown.
        Parameters:
        sourceVertex - source vertex of the edge.
        targetVertex - target vertex of the edge.
        clickable - the clickable edge to be added to this graph.
        Returns:
        true if this graph did not already contain the specified edge.
        See Also:
        Graph.addEdge(Object, Object, Object)
      • getOutgoingClickables

        public com.google.common.collect.ImmutableSet<Eventable> getOutgoingClickables​(StateVertex stateVertex)
        Description copied from interface: StateFlowGraph
        Returns a set of all clickables outgoing from the specified vertex.
        Specified by:
        getOutgoingClickables in interface StateFlowGraph
        Parameters:
        stateVertex - the state vertex.
        Returns:
        a set of the outgoing edges (clickables) of the stateVertex.
      • getIncomingClickable

        public com.google.common.collect.ImmutableSet<Eventable> getIncomingClickable​(StateVertex stateVertex)
        Description copied from interface: StateFlowGraph
        Returns a set of all edges incoming into the specified vertex.
        Specified by:
        getIncomingClickable in interface StateFlowGraph
        Parameters:
        stateVertex - the state vertex.
        Returns:
        a set of the incoming edges (clickables) of the stateVertex.
      • canGoTo

        public boolean canGoTo​(StateVertex source,
                               StateVertex target)
        Description copied from interface: StateFlowGraph
        Is it possible to go from s1 -> s2?
        Specified by:
        canGoTo in interface StateFlowGraph
        Parameters:
        source - the source state.
        target - the target state.
        Returns:
        true if it is possible (edge exists in graph) to go from source to target.
      • getShortestPath

        public com.google.common.collect.ImmutableList<Eventable> getShortestPath​(StateVertex start,
                                                                                  StateVertex end)
        Description copied from interface: StateFlowGraph
        Convenience method to find the Dijkstra shortest path between two states on the graph.
        Specified by:
        getShortestPath in interface StateFlowGraph
        Parameters:
        start - the start state.
        end - the end state.
        Returns:
        a list of shortest path of clickables from the state to the end
      • getAllStates

        public com.google.common.collect.ImmutableSet<StateVertex> getAllStates()
        Description copied from interface: StateFlowGraph
        Return all the states in the StateFlowGraph.
        Specified by:
        getAllStates in interface StateFlowGraph
        Returns:
        all the states on the graph.
      • getAllEdges

        public com.google.common.collect.ImmutableSet<Eventable> getAllEdges()
        Description copied from interface: StateFlowGraph
        Return all the edges in the StateFlowGraph.
        Specified by:
        getAllEdges in interface StateFlowGraph
        Returns:
        a Set of all edges in the StateFlowGraph
      • getNumberOfStates

        public int getNumberOfStates()
        Specified by:
        getNumberOfStates in interface StateFlowGraph
        Returns:
        The number of states, currently in the graph.
      • getNewStateName

        private String getNewStateName​(int id)
      • getDeepStates

        private List<StateVertex> getDeepStates​(StateVertex state)
        Parameters:
        state - The starting state.
        Returns:
        A list of the deepest states (states with no outgoing edges).