Class Wc

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

public class Wc
extends Command

The Wc class (a subclass of the abstract base class Command) implements the familiar unix command wc, which outputs a count of lines, words, and characters in each file. This class implements the abstract methods execute and getDescription inherited from the abstract base class Command.


Field Summary
protected  int myCharCount
          Number of characters in file.
protected  int myLineCount
          Number of lines in file.
protected  int myWordCount
          Number of words in file.
 
Constructor Summary
Wc()
           
 
Method Summary
protected  void doCount(java.lang.String filename)
          A helper function that counts the number of lines, words, and characters in the current file.
 java.lang.String execute(java.lang.String args)
          Executes the wc command and returns the result in the form of a String object.
 java.lang.String getDescription()
          Returns a description of the command.
protected  int getLineCount()
          A helper function that returns the line count of the current file.
protected  java.lang.String Update(java.lang.String filename)
          A helper function that updates the result to be passed back through execute with the counts of the number of lines, words, and characters in the current file.
 
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

myLineCount

protected int myLineCount
Number of lines in file.


myWordCount

protected int myWordCount
Number of words in file.


myCharCount

protected int myCharCount
Number of characters in file.

Constructor Detail

Wc

public Wc()
Method Detail

execute

public java.lang.String execute(java.lang.String args)
Executes the wc 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 wc command.

doCount

protected void doCount(java.lang.String filename)
A helper function that counts the number of lines, words, and characters in the current file.

Parameters:
filename - name of file to be counted.

Update

protected java.lang.String Update(java.lang.String filename)
A helper function that updates the result to be passed back through execute with the counts of the number of lines, words, and characters in the current file.

Parameters:
filename - name of file just counted.
Returns:
string containing counts associated with current file.

getLineCount

protected int getLineCount()
A helper function that returns the line count of the current file.

Returns:
myLineCount.

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.