Hi All,
I need to save a history of states over a few actions in a Java application, which I can later reload in order to restore the state at a certain action. In other words I have a screen which has a state associated with it and I need to store it as well as any changes in a history so that I can restore the state of the screen at any time. This is kind of like 'undo' but not exactly as the difference between two state can be very large and there are no well-defined actions that changes the states.
Let me explain with an example: A very basic screen state might just contain a single Map. In state A this Map contains a reference to "Object1" with key "Key1" and "Object2" with key "Key2". In state B the Map still contains the reference to "Object1", but "Object2" has been modified and an "Object3" has been added. I now need to be able to return to state A, which would involve "dropping" Object3 and restoring Object2 to its previous state. I cannot define any custom "undo actions" as I do not know what changes were made to Object2 or even what the type of Object2 is. Further, because the reference remains the same for Object2 in state A and B, those changes are reflected in state A so Object2 isn't the same as it was.
I realize the best solution is to implement clone methods, but as I need to support all types of Objects (including primitives and standard collections) this isn't feasible. I thought about using serializable, where I would serialize the Map as soon as a state transition happens and then deserialize it when it is needed again, but it seems like a very ugly solution.
Does anybody have any other ideas? Thank you, Ristretto