summaryrefslogtreecommitdiff
path: root/tutorials/java/src/phpdbg/ui/CommandHistory.java
diff options
context:
space:
mode:
authorkrakjoe <joe.watkins@live.co.uk>2013-11-29 09:35:33 +0000
committerkrakjoe <joe.watkins@live.co.uk>2013-11-29 09:35:33 +0000
commit216e3668d60429b32b4e01570af3377f00d6dfbb (patch)
tree0ce01ae384b27ad989cf01096b5160699c5d645e /tutorials/java/src/phpdbg/ui/CommandHistory.java
parentbd49a0f1444885c1724b5322ab786ae634e2222a (diff)
downloadphp-git-216e3668d60429b32b4e01570af3377f00d6dfbb.tar.gz
...
Diffstat (limited to 'tutorials/java/src/phpdbg/ui/CommandHistory.java')
-rw-r--r--tutorials/java/src/phpdbg/ui/CommandHistory.java49
1 files changed, 49 insertions, 0 deletions
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<String> {
+ 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