org.sc3d.apt.sss.v3
Class Sentence

java.lang.Object
  extended by org.sc3d.apt.sss.v3.Sentence

public class Sentence
extends java.lang.Object

Represents a sequence of characters that need to be parsed, and allows error messages to be attached to it.


Field Summary
 int length
          The number of characters in this Sentence.
 
Constructor Summary
Sentence(char[] cs)
          Constructs a Sentence given an array of characters.
 
Method Summary
 void addError(java.lang.String message, int index, int length)
          Attaches an error message to part of this Sentence.
 void addErrorAtEnd(java.lang.String message)
          Equivalent to 'addError(message, length, 0).
 int countErrors()
          Returns the number of errors attached to this Sentence.
 char get(int index)
          Returns the character at 'index'.
 java.lang.String getString(int index, int length)
          Returns part of this Sentence as a String.
static void main(java.lang.String[] args)
          Takes one argument: a filename.
 void printErrorReport(java.io.PrintStream out, int maxErrors)
          Prints an error report to 'out'.
static Sentence readFile(java.lang.String filename)
          Reads the named file and returns it as a Sentence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

public final int length
The number of characters in this Sentence.

Constructor Detail

Sentence

public Sentence(char[] cs)
Constructs a Sentence given an array of characters.

Method Detail

get

public char get(int index)
Returns the character at 'index'.


getString

public java.lang.String getString(int index,
                                  int length)
Returns part of this Sentence as a String.

Parameters:
index - the index at which the desired String starts.
length - the length of the desired String.

addError

public void addError(java.lang.String message,
                     int index,
                     int length)
Attaches an error message to part of this Sentence. This method may do nothing if there is already an error message attached nearby.

Parameters:
message - the error message.
index - the index of the first character to which the error message applies. Must be in the range from '0' to 'this.length' inclusive.
length - the number of characters to which this error message applies.

addErrorAtEnd

public void addErrorAtEnd(java.lang.String message)
Equivalent to 'addError(message, length, 0).


countErrors

public int countErrors()
Returns the number of errors attached to this Sentence.


printErrorReport

public void printErrorReport(java.io.PrintStream out,
                             int maxErrors)
Prints an error report to 'out'.

Parameters:
out - a PrintStream to which to print the error report.
maxErrors - the maximum number of errors to print.

readFile

public static Sentence readFile(java.lang.String filename)
                         throws java.io.IOException
Reads the named file and returns it as a Sentence.

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Takes one argument: a filename. Reads the file, adds errors at random, then prints an error report.

Throws:
java.io.IOException