Created
March 5, 2015 15:41
-
-
Save alexandreaquiles/7f96ce61e4802efc356d to your computer and use it in GitHub Desktop.
Exemplo de pequena implementação (não muito eficiente) de undo.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.LinkedList; | |
public class GerenciadorDeUndo { | |
private LinkedList<String> digitados = new LinkedList<>(); | |
public void adiciona(String texto){ | |
digitados.add(texto); | |
} | |
public String desfaz(){ | |
digitados.pollLast(); //remove ultimo elemento | |
return digitados.peekLast(); //retorna o penultimo | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GerenciadorDeUndoTest { | |
@Test | |
public void deveDesfazer(){ | |
GerenciadorDeUndo undo = new GerenciadorDeUndo(); | |
undo.adiciona("texto1"); | |
undo.adiciona("texto2"); | |
undo.adiciona("texto3"); | |
Assert.assertEquals("texto2", undo.desfaz()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment