From 216e3668d60429b32b4e01570af3377f00d6dfbb Mon Sep 17 00:00:00 2001 From: krakjoe Date: Fri, 29 Nov 2013 09:35:33 +0000 Subject: ... --- tutorials/java/src/phpdbg/ui/CommandHistory.java | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tutorials/java/src/phpdbg/ui/CommandHistory.java (limited to 'tutorials/java/src/phpdbg/ui/CommandHistory.java') diff --git a/tutorials/java/src/phpdbg/ui/CommandHistory.java b/tutorials/java/src/phpdbg/ui/CommandHistory.java new file mode 100644 index 0000000000..b8a3b0ff0a --- /dev/null +++ b/tutorials/java/src/phpdbg/ui/CommandHistory.java @@ -0,0 +1,49 @@ +package phpdbg.ui; + + +import java.util.ArrayList; + +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * Implement a simple history list for command input + * @author krakjoe + */ +public class CommandHistory extends ArrayList { + private Integer position = new Integer(0); + + public CommandHistory() { + super(); + } + + @Override public boolean add(String text) { + String last = last(); + if (text != null) { + if (last == null || !last.equals(text)) { + if (super.add(text)) { + position = size(); + return true; + } + } + } + return false; + } + + public String last() { + if (position >= 1) { + position--; + return get(position); + } else return new String(); + } + + public String next() { + if (position+1 < size()) { + position++; + return get(position); + } else return new String(); + } +} \ No newline at end of file -- cgit v1.2.1