From cf40c1951f4f0f26090226fb4969ca147341a031 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 02 Oct 2009 22:24:56 +0000 Subject: LP 439980 : Refactored the XMLSerializer to support complex components; Corrected specs for the addons properties and constructor parameters names; Moved all existing actions and events to components (except a few left in code for testing purposes) --- (limited to 'tutorius/core.py') diff --git a/tutorius/core.py b/tutorius/core.py index dd2435e..41089f1 100644 --- a/tutorius/core.py +++ b/tutorius/core.py @@ -258,6 +258,42 @@ class State(object): tutorial. """ self._event_filters = [] + + def is_identical(self, otherState): + """ + Compares two states and tells whether they contain the same states and + +` """ + if not isinstance(otherState, State): + return False + if self.name != otherState.name: + return False + + # Do they have the same actions? + if len(self._actions) != len(otherState._actions): + return False + for act in self._actions: + found = False + for otherAct in otherState._actions: + if act.is_identical(otherAct): + found = True + break + if found == False: + return False + + # Do they have the same event filters? + if len(self._actions) != len(otherState._actions): + return False + for event in self._event_filters: + found = False + for otherEvent in otherState._event_filters: + if event.is_identical(otherEvent): + found = True + break + if found == False: + return False + + return True class FiniteStateMachine(State): """ @@ -526,3 +562,43 @@ class FiniteStateMachine(State): for st in self._states.itervalues(): out_string += st.name + ", " return out_string + + def is_identical(self, otherFSM): + """ + Compares the elements of two FSM to ensure and returns true if they have the + same set of states, containing the same actions and the same event filters. + + @returns True if the two FSMs have the same content false otherwise + """ + if not isinstance(otherFSM, FiniteStateMachine): + return False + + if not (self.name == otherFSM.name) or \ + not (self.start_state_name == otherFSM.start_state_name): + return False + + if len(self._actions) != len(otherFSM._actions): + return False + # Test that we have all the same FSM level actions + for act in self._actions: + found = False + for otherAct in otherFSM._actions: + if act.is_identical(otherAct): + found = True + break + if found == False: + return False + + if len(self._states) != len(otherFSM._states): + return False + + for state in self._states.itervalues(): + found = False + for otherState in otherFSM._states.itervalues(): + if state.is_identical(otherState): + found = True + break + if found == False: + return False + + return True -- cgit v0.9.1