Class CmdStringHistory

  extended by

public class CmdStringHistory
extends java.lang.Object

Sebastian Loh This class provides a "history" function for the console command line. It based on two stacks which contain the command strings.

Constructor Summary
          Default constructor
Method Summary
 void add(java.lang.String cmd)
          resets the history and adds a new String into it.
 void addSucc(java.lang.String cmd)
          This is used if a new command is typed into the cmdField but ENTER wasn't pressed yet.
 void clear()
          Removes all elements from the history.
 java.util.List<java.lang.String> getHistoryElements(int quantity)
 java.lang.String getPredecessor()
          returns the previous command
 java.lang.String getSuccessor()
 void reset()
          resets the history
 void setHistoryElements(java.util.List<java.lang.String> elementList)
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CmdStringHistory()
Default constructor

Method Detail


public void add(java.lang.String cmd)
resets the history and adds a new String into it.

cmd -


public void addSucc(java.lang.String cmd)
This is used if a new command is typed into the cmdField but ENTER wasn't pressed yet. Then the typed command needs to be remembered but only then. The console doesn't know the state of the history, so it tries to add a succeeding command every time a UP key is pressed. Example: the history is reseted and predecessors contains: [a,b,c] successors is empty. In the cmdField the user typed "d" but didn't press ENTER yet. Then she presses UP to get the previous command, which is in this case "c". The history has to remember the unconfirmed "d" command in that case, because we want a user friendly interface. Now the situation is: the user sees: "c" the history state is predecessors: [a,b] successors: [c,d] d was never confirmed, but we want to remember it. If the user now modifies the "c" command, eg. adding a "1" -> "c1" and if she presses UP again, to get the previous command of "c", the "c1" will not added to the history, because it is not reseted.

cmd -


public java.lang.String getPredecessor()
returns the previous command



public java.lang.String getSuccessor()
the succeeding command


public void reset()
resets the history


public java.util.List<java.lang.String> getHistoryElements(int quantity)


public void clear()
Removes all elements from the history.


public void setHistoryElements(java.util.List<java.lang.String> elementList)