Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package serie03;
- import java.util.LinkedList;
- public class Clear extends AbstractCommand {
- // attribut
- private LinkedList<String> backUp;
- // constructeur
- public Clear(Text text) {
- super(text);
- backUp = new LinkedList<String>();
- }
- // requete
- public LinkedList<String> getBackUp() {
- return backUp;
- }
- // commande
- @Override
- void doIt() {
- assert canDo();
- this.getBackUp().clear();
- for (int i = 1; i <= getText().getLinesNb(); i++) {
- this.getBackUp().add(getText().getLine(i));
- }
- this.getText().clear();
- }
- @Override
- void undoIt() {
- assert canUndo();
- for (int i = 1; i <= this.getBackUp().size(); i++) {
- this.getText().insertLine(i, this.getBackUp().get(i - 1));
- }
- backUp.clear();
- }
- }
- package serie03;
- public class InsertLine extends AbstractCommand {
- // attribut
- private int index;
- private String line;
- // constructeur
- public InsertLine(Text text, int lines, String chain) {
- super(text);
- if (lines <= 0) {
- throw new IllegalArgumentException("ligne non accessible");
- } else if (chain == null) {
- throw new IllegalArgumentException("aucune chaine a ecrire");
- }
- index = lines;
- line = chain;
- }
- // requete
- public int getIndex() {
- return index;
- }
- public String getLine() {
- return line;
- }
- // commmande
- public boolean canDo() {
- return
- super.canDo()
- && getIndex() <= getText().getLinesNb() + 1;
- }
- public boolean canUndo() {
- return
- super.canUndo()
- && getIndex() <= getText().getLinesNb();
- }
- @ Override
- void doIt() {
- assert canDo();
- getText().insertLine(getIndex(), getLine());
- }
- @Override
- void undoIt() {
- assert canUndo();
- getText().deleteLine(getIndex());
- }
- }
Add Comment
Please, Sign In to add comment