Building Parsers with Java

sjm.imperative
Class ReadCommand

java.lang.Object
  |
  +--sjm.imperative.Command
        |
        +--sjm.imperative.ReadCommand

public class ReadCommand
extends Command

This command, when executed, reads in a string and assigns it to a supplied variable.


Field Summary
protected  java.io.BufferedReader reader
           
protected  Variable variable
           
 
Constructor Summary
ReadCommand(Variable variable)
          Construct a "read" command to read a value, assigning it to the supplied variable.
ReadCommand(Variable variable, java.io.BufferedReader reader)
          Construct a "read" command to read a value from the supplied reader, assigning the value to the supplied variable.
ReadCommand(Variable variable, java.io.InputStream in)
          Construct a "read" command to read a value from the supplied input stream, assigning the value to the supplied variable.
 
Method Summary
 void execute()
          Read in a string from this object's input reader, and assign the string to this object's variable.
 java.lang.String toString()
          Returns a string description of this read command.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

variable

protected Variable variable

reader

protected java.io.BufferedReader reader
Constructor Detail

ReadCommand

public ReadCommand(Variable variable)
Construct a "read" command to read a value, assigning it to the supplied variable. This constructor sets the command to read from System.in.
Parameters:
Variable - the variable to assign to

ReadCommand

public ReadCommand(Variable variable,
                   java.io.BufferedReader reader)
Construct a "read" command to read a value from the supplied reader, assigning the value to the supplied variable.
Parameters:
Variable - the variable to assign to
BufferedReader - where to read from

ReadCommand

public ReadCommand(Variable variable,
                   java.io.InputStream in)
Construct a "read" command to read a value from the supplied input stream, assigning the value to the supplied variable.
Parameters:
Variable - the variable to assign to
InputStream - where to read from
Method Detail

execute

public void execute()
Read in a string from this object's input reader, and assign the string to this object's variable.
Overrides:
execute in class Command

toString

public java.lang.String toString()
Returns a string description of this read command.
Overrides:
toString in class java.lang.Object
Returns:
a string description of this read command

by Steve Metsker