com.tomgibara.pronto.state.impl
Class StateGraphImpl<S,L>

java.lang.Object
  extended by com.tomgibara.pronto.state.impl.StateGraphImpl<S,L>
All Implemented Interfaces:
StateGraph<S,L>

public class StateGraphImpl<S,L>
extends java.lang.Object
implements StateGraph<S,L>


Method Summary
 boolean equals(java.lang.Object obj)
           
 S getInitialState()
          The single initial state.
 java.util.Set<S> getInitialStates()
          An immutable set of the states that are not the target of any transition.
 java.util.Set<java.util.List<StateTransition<S,L>>> getMultiPaths(java.util.Set<S> initial, java.util.Set<S> terminal, PathType type)
          A set containing every possible path (represented as a list of transitions) from any initial state to any terminal state.
 java.util.List<StateTransition<S,L>> getPath(S initial, S terminal, PathType type)
          A convenience method that may be called to obtain the single existing path from an initial state to a terminal state.
 java.util.Set<java.util.List<StateTransition<S,L>>> getPaths(S initial, S terminal, PathType type)
          A set containing every possible path (represented as a list of transitions) from the initial state to the terminal state.
 S getTerminalState()
          The single terminal state.
 java.util.Set<S> getTerminalStates()
          An immutable set of the states that are not the source of any transition.
 StateTransition<S,L> getTransition(S source, L label, S target)
          Obtains the specified state transition from this graph.
 java.util.Set<StateTransition<S,L>> getTransitionsMatching(S source, L label, S target)
          Returns an immutable set of all transitions that match the supplied parameters.
 int hashCode()
           
 StateGraphEditor<S,L> newEditor()
          Obtains an editor which may be used to edit a copy of this graph.
 java.util.Set<S> states()
          The set of states in this graph.
 java.lang.String toString()
           
 java.util.Set<StateTransition<S,L>> transitions()
          An immutable set containing every transition in the graph.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

states

public java.util.Set<S> states()
Description copied from interface: StateGraph
The set of states in this graph. The presence of a state in this set does not guarantee that there is a transition on that state.

Specified by:
states in interface StateGraph<S,L>
Returns:
the set of states, may be empty

getTerminalStates

public java.util.Set<S> getTerminalStates()
Description copied from interface: StateGraph
An immutable set of the states that are not the source of any transition.

Specified by:
getTerminalStates in interface StateGraph<S,L>
Returns:
the set of terminal states, may be empty.

getTerminalState

public S getTerminalState()
                   throws ProntoStateException
Description copied from interface: StateGraph
The single terminal state. This is a convenience method for situations where the client code knows that there is at most one terminal state.

Specified by:
getTerminalState in interface StateGraph<S,L>
Returns:
the single terminal state or null
Throws:
ProntoStateException - if there is more than terminal state

getInitialStates

public java.util.Set<S> getInitialStates()
Description copied from interface: StateGraph
An immutable set of the states that are not the target of any transition.

Specified by:
getInitialStates in interface StateGraph<S,L>
Returns:
the set of initial states, may be empty

getInitialState

public S getInitialState()
                  throws ProntoStateException
Description copied from interface: StateGraph
The single initial state. This is a convenience method for situations where the client code knows that there is at most one initial state.

Specified by:
getInitialState in interface StateGraph<S,L>
Returns:
the single initial state or null
Throws:
ProntoStateException - if there is more than initial state

getTransition

public StateTransition<S,L> getTransition(S source,
                                          L label,
                                          S target)
Description copied from interface: StateGraph
Obtains the specified state transition from this graph. To match multiple transitions use the getTransitionsMatching method.

Specified by:
getTransition in interface StateGraph<S,L>
Parameters:
source - the source of the transition, not null
label - the transition's label, not null
target - the target of the transition, not null
Returns:
the state transition in this graph with the exact source, label and target supplied, or null

getTransitionsMatching

public java.util.Set<StateTransition<S,L>> getTransitionsMatching(S source,
                                                                  L label,
                                                                  S target)
Description copied from interface: StateGraph
Returns an immutable set of all transitions that match the supplied parameters. Supplying null for every parameter results in every transition being returned.

Specified by:
getTransitionsMatching in interface StateGraph<S,L>
Parameters:
source - the required transition source, or null to match any source
label - the required transition label, or null to match any label
target - the required transition target, or null to match any target
Returns:
an immutable set of the matching transitions

transitions

public java.util.Set<StateTransition<S,L>> transitions()
Description copied from interface: StateGraph
An immutable set containing every transition in the graph.

Specified by:
transitions in interface StateGraph<S,L>
Returns:
an immutable set containing every transition in the graph

getMultiPaths

public java.util.Set<java.util.List<StateTransition<S,L>>> getMultiPaths(java.util.Set<S> initial,
                                                                         java.util.Set<S> terminal,
                                                                         PathType type)
Description copied from interface: StateGraph
A set containing every possible path (represented as a list of transitions) from any initial state to any terminal state. Paths may contain cycles but cannot be empty. If a null terminal set is supplied then all paths originating from the initial set are returned.

Specified by:
getMultiPaths in interface StateGraph<S,L>
Parameters:
initial - the states at which paths begin, not null
terminal - the states at which paths terminate, may be null
type - a constraint on the paths
Returns:
an immutable set of the paths from initial states to terminal states

getPaths

public java.util.Set<java.util.List<StateTransition<S,L>>> getPaths(S initial,
                                                                    S terminal,
                                                                    PathType type)
Description copied from interface: StateGraph
A set containing every possible path (represented as a list of transitions) from the initial state to the terminal state. Paths may contain cycles but cannot be empty. If a null terminal state is supplied then all paths originating from the initial state are returned.

Specified by:
getPaths in interface StateGraph<S,L>
Parameters:
initial - the state at which paths begin, not null
terminal - the state at which paths terminate, may be null
type - a constraint on the paths
Returns:
an immutable set of the paths from initial states to terminal states

getPath

public java.util.List<StateTransition<S,L>> getPath(S initial,
                                                    S terminal,
                                                    PathType type)
                                             throws ProntoStateException
Description copied from interface: StateGraph
A convenience method that may be called to obtain the single existing path from an initial state to a terminal state. If no path exists null is returned. If a null terminal state is supplied then the single path originating from the initial state is returned.

Specified by:
getPath in interface StateGraph<S,L>
Parameters:
initial - the state at which path begins, not null
terminal - the state at which path terminates, may be null
type - a constraint on the path
Returns:
the single path from an initial state to a terminal state, or null
Throws:
ProntoStateException - if there is more than one path between an initial state and a terminal state

newEditor

public StateGraphEditor<S,L> newEditor()
Description copied from interface: StateGraph
Obtains an editor which may be used to edit a copy of this graph. A new editor is returned on each call to this method.

Specified by:
newEditor in interface StateGraph<S,L>
Returns:
an editor over this graph.

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2006-2007 Tom Gibara. All Rights Reserved.