edu.cs.ai.kreator.ui.cli
Class CmdStringHistory

java.lang.Object
  extended by edu.cs.ai.kreator.ui.cli.CmdStringHistory

public class CmdStringHistory
extends java.lang.Object

Author:
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
CmdStringHistory()
          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

CmdStringHistory

public CmdStringHistory()
Default constructor

Method Detail

add

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

Parameters:
cmd -

addSucc

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.

Parameters:
cmd -

getPredecessor

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

Returns:

getSuccessor

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

reset

public void reset()
resets the history


getHistoryElements

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

clear

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


setHistoryElements

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