gshute.ioutil
Class CommandTable

java.lang.Object
  |
  +--gshute.ioutil.CommandTable

public class CommandTable
extends java.lang.Object

A CommandTable provides a means for storing, retrieving, and executing commands for command-driven interpreter programs.


Field Summary
protected  java.util.Vector commands
          commands is the list of commands in this CommandTable.
protected  int maxNameLength
          maxNameLength is the length of the longest command name in this CommandTable.
protected  int maxSynopsisLength
          maxSynopsisLength is the length of the longest synopsis in this CommandTable.
 
Constructor Summary
CommandTable()
          new CommandTable() returns a new empty CommandTable.
 
Method Summary
 void add(Command comm)
          ct.add(comm) adds comm to ct.
 void displayHelp(java.lang.String str)
          ct.displayHelp(String str) displays full descriptions for Commands in ct whose name matches str.
 void displayMenu()
          ct.displayMenu() displays a menu of commands in ct.
static Command doNothingCommand(java.lang.String str)
          CommandTable.doNothingCommand(str) returns a Command that does nothing.
 void execute(LineScanner commLine)
          ct.execute(commLine) executes the Command whose name is the first word of commLine and whose arguments are the remaining words of commLine.
protected  Command getCommand(java.lang.String str)
          getCommand(str) returns the Command in this CommandTable whose name matches str.
protected  java.util.Enumeration getCommandsMatching(java.lang.String str)
          getCommandsMatching(str) returns an Enumeration of Commands in this CommandTable whose names match str.
 Command helpCommand(java.lang.String str)
          ct.helpCommand(str) returns a Command named str.
protected  int matchCount(java.lang.String str)
          ct.matchCount(str) returns the number of Commands in ct whose name contains str as a prefix.
protected  int prefixCount(java.lang.String str)
          ct.prefixCount(str) returns the number of Commands in ct whose name is a prefix of str.
static Command quitCommand(java.lang.String str)
          CommandTable.quitCommand(str) returns a Command that terminates the program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

commands

protected java.util.Vector commands
commands is the list of commands in this CommandTable.

maxNameLength

protected int maxNameLength
maxNameLength is the length of the longest command name in this CommandTable.

maxSynopsisLength

protected int maxSynopsisLength
maxSynopsisLength is the length of the longest synopsis in this CommandTable.
Constructor Detail

CommandTable

public CommandTable()
new CommandTable() returns a new empty CommandTable.
Method Detail

add

public void add(Command comm)
ct.add(comm) adds comm to ct.

Preconditions:
The name of comm is not an empty string.
The name of comm is not a prefix of the name of any Command in ct.
No name of a Command in ct is a prefix of the name of comm.


execute

public void execute(LineScanner commLine)
ct.execute(commLine) executes the Command whose name is the first word of commLine and whose arguments are the remaining words of commLine.

displayMenu

public void displayMenu()
ct.displayMenu() displays a menu of commands in ct.

displayHelp

public void displayHelp(java.lang.String str)
ct.displayHelp(String str) displays full descriptions for Commands in ct whose name matches str.

helpCommand

public Command helpCommand(java.lang.String str)
ct.helpCommand(str) returns a Command named str. If this Command is called with no arguments then it displays a menu of commands in ct. If it is called with one or more arguments then it displays full decriptions of commands in ct that match the arguments.

doNothingCommand

public static Command doNothingCommand(java.lang.String str)
CommandTable.doNothingCommand(str) returns a Command that does nothing. The command name for this Command is specified by str.

quitCommand

public static Command quitCommand(java.lang.String str)
CommandTable.quitCommand(str) returns a Command that terminates the program. The command name for this Command is specified by str.

matchCount

protected int matchCount(java.lang.String str)
ct.matchCount(str) returns the number of Commands in ct whose name contains str as a prefix.

prefixCount

protected int prefixCount(java.lang.String str)
ct.prefixCount(str) returns the number of Commands in ct whose name is a prefix of str.

getCommand

protected Command getCommand(java.lang.String str)
getCommand(str) returns the Command in this CommandTable whose name matches str.

Precondition:
str is the name of a Command in ct.


getCommandsMatching

protected java.util.Enumeration getCommandsMatching(java.lang.String str)
getCommandsMatching(str) returns an Enumeration of Commands in this CommandTable whose names match str.