stockportfolio
Class CommandReader

java.lang.Object
  extended bystockportfolio.CommandReader
All Implemented Interfaces:
java.lang.Runnable

public class CommandReader
extends java.lang.Object
implements java.lang.Runnable

Simple text-based shell for stock portfolio manager. Class CommandReader is a text-based UI for the stock portfolio project. It implements a very simple shell with four commands:

BUY stockname quantity price date
SELL stockname quantity price date
REPORT
EXIT

All commands are case insensitive, but the stockname case sensitivity depends on the underlying portfolio implementation. quantity and price are doubles and date should be in mm/dd/yyyy format. Any unrecognized entry will print a usage string, so HELP and ? will both provide help (as will ASDFASDFASDF.) There are only three methods, setIn, setOut and run. This should be enough to provide simple console-based or file- based exercising of the portfolio functions. The main method simply hooks in to System.in, out to System.out and calls run.

Author:
carlson

Field Summary
static java.lang.String BUY_COMMAND
          The BUY_COMMAND text for the CommandReader shell.
static java.lang.String EXIT_COMMAND
          The EXIT_COMMAND text for the CommandReader shell.
static java.lang.String REPORT_COMMAND
          The REPORT_COMMAND text for the CommandReader shell.
static java.lang.String SELL_COMMAND
          The SELL_COMMAND text for the CommandReader shell.
static java.lang.String USAGE
          The USAGE string for the CommandReader shell.
 
Constructor Summary
CommandReader()
          Default constructor sets in and out to System.in and System.out, respectively.
 
Method Summary
static void main(java.lang.String[] args)
          Simply sets up a command reader and runs it.
 void run()
          The run method initiates the command processor
 void setIn(java.io.BufferedReader in)
          setIn allows for redirection of input so that you can get commands from a file.
 void setOut(java.io.PrintWriter out)
          setOut allows for redirection of output so that you can send results to a file (or anywhere else)
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUY_COMMAND

public static final java.lang.String BUY_COMMAND
The BUY_COMMAND text for the CommandReader shell.

See Also:
Constant Field Values

SELL_COMMAND

public static final java.lang.String SELL_COMMAND
The SELL_COMMAND text for the CommandReader shell.

See Also:
Constant Field Values

REPORT_COMMAND

public static final java.lang.String REPORT_COMMAND
The REPORT_COMMAND text for the CommandReader shell.

See Also:
Constant Field Values

EXIT_COMMAND

public static final java.lang.String EXIT_COMMAND
The EXIT_COMMAND text for the CommandReader shell.

See Also:
Constant Field Values

USAGE

public static final java.lang.String USAGE
The USAGE string for the CommandReader shell.

See Also:
Constant Field Values
Constructor Detail

CommandReader

public CommandReader()
Default constructor sets in and out to System.in and System.out, respectively.

Method Detail

setIn

public void setIn(java.io.BufferedReader in)
setIn allows for redirection of input so that you can get commands from a file.

Parameters:
in - The BufferedReader that will be used for all subsequent input

setOut

public void setOut(java.io.PrintWriter out)
setOut allows for redirection of output so that you can send results to a file (or anywhere else)

Parameters:
out - The PrintWriter that all subsequent output will be sent to.

run

public void run()
The run method initiates the command processor

Specified by:
run in interface java.lang.Runnable
See Also:
Runnable.run()

main

public static void main(java.lang.String[] args)
Simply sets up a command reader and runs it.

Parameters:
args - The first argument, if any, will be treated as the name of a file from which to redirect input. The second argument, if any, will be treated as the name of a file to which output will be redirected.