Skip to content

Instantly share code, notes, and snippets.

@alexandreaquiles
Created March 5, 2015 15:41
Show Gist options
  • Save alexandreaquiles/7f96ce61e4802efc356d to your computer and use it in GitHub Desktop.
Save alexandreaquiles/7f96ce61e4802efc356d to your computer and use it in GitHub Desktop.
Exemplo de pequena implementação (não muito eficiente) de undo.
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
}
}
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