Class Head

java.lang.Object
  |
  +--Command
        |
        +--Head

public class Head
extends Command

The Head class (a subclass of the abstract base class Command) implements the familiar unix command head, which outputs the first number of lines of each file. This class implements the abstract methods execute and getDescription inherited from the abstract base class Command.


Field Summary
protected  java.util.Vector fileList
          A vector containing string arguments to head - i.e. filenames.
protected  int numLinesToRead
          An int value containing the number of lines to read from file.
protected  java.util.Vector numList
          A vector containing numerical arguments to head.
 
Constructor Summary
Head()
           
 
Method Summary
 java.lang.String execute(java.lang.String args)
          Executes the head command and returns the result in the form of a String object.
protected  java.lang.String fileToString(java.lang.String filename)
          A helper function that converts the given file to a String object containing the number of lines specified by numLinesToRead.
 java.lang.String getDescription()
          Returns a description of the command.
protected  void processArgs(java.lang.String argLine)
          A helper function that parses the arguments of this command into appropriate containers.
 
Methods inherited from class Command
ExpandArgs
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numList

protected java.util.Vector numList
A vector containing numerical arguments to head.


fileList

protected java.util.Vector fileList
A vector containing string arguments to head - i.e. filenames.


numLinesToRead

protected int numLinesToRead
An int value containing the number of lines to read from file.

Constructor Detail

Head

public Head()
Method Detail

execute

public java.lang.String execute(java.lang.String args)
Executes the head command and returns the result in the form of a String object.

Specified by:
execute in class Command
Parameters:
args - arguments for this command.
Returns:
the string result of executing the head command.

fileToString

protected java.lang.String fileToString(java.lang.String filename)
A helper function that converts the given file to a String object containing the number of lines specified by numLinesToRead.

Parameters:
filename - name of file to be converted to a string.
Returns:
a string containing the contents of the specified file.

processArgs

protected void processArgs(java.lang.String argLine)
A helper function that parses the arguments of this command into appropriate containers.

Parameters:
argLine - arguments to be parsed.

getDescription

public java.lang.String getDescription()
Description copied from class: Command
Returns a description of the command.

Specified by:
getDescription in class Command
Returns:
the name of the command.