bb.util
Class CommandLineInterface

java.lang.Object
  extended by bb.util.CommandLineInterface

public final class CommandLineInterface
extends Object

Illustrates one way to quickly implement a simple command line interface (CLI).

The CLI supported by this class consists of the following:

  1. upon startup, all the commands available to the user are printed on the console (System.out)
  2. thereafter, the program waits for the user to type a command on the console (System.in). Valid input is either the number or name of a command, followed by hitting the Enter key.
There are obviously many major limitations with the above CLI (e.g. no options or arguments to commands are currently supported); many of these deficiencies could be addressed by extra coding...

What makes this class interesting is that it allows the programmer to add new commands extremely quickly: all you need to do is write a Java method (see CommandLineInterface.Commands for details).

This class is multithread safe: it is stateless.

Author:
Brent Boyer

Nested Class Summary
private static class CommandLineInterface.Commands
          Whenever you wish to add a command to the CommandLineInterface class, all that you need to do is add it as a method of this class.
private static class CommandLineInterface.StdinReader
           
 
Constructor Summary
private CommandLineInterface()
          This sole private constructor ensures non-instantiability outside of this class.
 
Method Summary
static void main(String[] args)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommandLineInterface

private CommandLineInterface()
This sole private constructor ensures non-instantiability outside of this class.

Method Detail

main

public static void main(String[] args)