Mercurial > dive4elements > framework
changeset 201:973f244ed568
Improved the TransitionEngine with a method that determines if a State B is reachable from a State A.
artifacts/trunk@1445 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 09 Mar 2011 15:48:06 +0000 |
parents | 62dd8438885f |
children | c03d3a872cd2 |
files | ChangeLog artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java |
diffstat | 2 files changed, 40 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Wed Mar 09 14:02:03 2011 +0000 +++ b/ChangeLog Wed Mar 09 15:48:06 2011 +0000 @@ -1,3 +1,8 @@ +2011-03-09 Ingo Weinzierl <ingo@intevation.de> + + * artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java: + New method to determine if a state B is reachable from a state A. + 2011-03-09 Ingo Weinzierl <ingo@intevation.de> * artifact-database/src/main/java/de/intevation/artifactdatabase/data/DefaultStateData.java:
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java Wed Mar 09 14:02:03 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/transition/TransitionEngine.java Wed Mar 09 15:48:06 2011 +0000 @@ -85,6 +85,10 @@ List<Transition> transitions = getTransitions(state); List<State> reachable = new ArrayList<State>(); + if (transitions == null) { + return reachable; + } + for (Transition t: transitions) { if (t.isValid(state)) { reachable.add(engine.getState(t.getTo())); @@ -93,5 +97,36 @@ return reachable; } + + + /** + * Determines if a state with a given identifier is reachable from a current + * state. + * + * @param targetId The identifier of the target state. + * @param state The start state. + * @param stateEngine The StateEngine. + * + * @return true, if the target state is reachable, otherwise false. + */ + public boolean isStateReachable( + String targetId, + State state, + StateEngine stateEngine) + { + List<State> reachable = getReachableStates(state, stateEngine); + + if (reachable == null || reachable.size() == 0) { + return false; + } + + for (State s: reachable) { + if (targetId.equals(s.getID())) { + return true; + } + } + + return false; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :