I want to ask a question about List in Java.
It is easy to implement delete,add and search an element in a list. But how to implement the undo and redo of a list in Java?
can anyone help me on this?
I want to ask a question about List in Java.
It is easy to implement delete,add and search an element in a list. But how to implement the undo and redo of a list in Java?
can anyone help me on this?
You might be looking to implement a Command Design Pattern
for this. A decent simplified example for List
can be found here http://www.algosome.com/articles/implementing-undo-redo-java.html
I guess you want to undo and redo the operations like delete and add on a list.
Just use another list with indexing capabilities for Undo and Redo, e.g. an ArrayList:
You mean like delete item from list and undo it? You can easily create new class for a list and define properties like: last performed action + store the origin value (and possibly index) of the effected item. The same for redo (at least for one step in redo and undo). If you don't care about order of the items (or you can order them easily), then define list of last performed actions and list of origin values. So for example: lastAction[0]="delete"; lastElement[0] = 1; // means you deleted 1 from the list
That's the first and dummy idea how to that. Perhaps there are some issues to consider...
You need binding to do that.
To me this is the most efficient way to do that. This question at SO can give you some hints regarding from where to start.
© 2022 - 2024 — McMap. All rights reserved.