ITI0011:Loeng 11

Allikas: Kursused
Mine navigeerimisribale Mine otsikasti

Loengus kasutatav lähtekood:

<source lang="java">

import java.util.ArrayList; import java.util.Arrays; import java.util.List;

public class UndoActionsExample {

public static class Element { public Integer number; }

public static abstract class Action { abstract void undo(); }

public static class AddAction extends Action { @Override void undo() { }

}

public static class ChangeAction extends Action {

@Override void undo() { } }

public static class DeleteAction extends Action { @Override void undo() { }

}

static List<Action> actions = new ArrayList<Action>();

static List<Element> elements = new ArrayList<Element>();

public static void main(String[] args) {

addNumber(10); addNumber(20); addNumber(30); removeNumber(1); changeNumber(0, 5); print();

undo(); print(); undo(); print(); undo(); print(); undo(); print(); undo(); print();


}

public static void addNumber(Integer number) { }

public static void changeNumber(int index, Integer number) { }

public static void removeNumber(int index) { }

public static void print() { System.out.println(Arrays.toString(elements.toArray())); } public static void printActions() { System.out.println(Arrays.toString(actions.toArray())); }

public static void undo() { }

}

</source>