Package apg
Class Utilities.LineCatalog
- java.lang.Object
-
- apg.Utilities.LineCatalog
-
- Enclosing class:
- Utilities
public static class Utilities.LineCatalog extends java.lang.Object
A class for reading a text file and cataloging its text lines. A catalog record is generated for each text line. The records have information about the line number, the offset to the first character of the line and the line length.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Utilities.LineCatalog.Line
Class defining a catalog record for an individual line of text.
-
Constructor Summary
Constructors Constructor Description LineCatalog(char[] inputArray)
ConstructorLineCatalog(java.lang.String inputString)
Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the catalog of all lines.void
displayErrors(java.io.PrintStream out)
Displays all errors encountered during the cataloging, if any.void
displayWarnings(java.io.PrintStream out)
Displays all warnings issued during the cataloging, if any.int
getErrorCount()
Get the number of errors encountered during the cataloging.Utilities.LineCatalog.Line
getLine(int lineno)
Retrieves a single catalog Line by line number.int
getLineCount()
Get the number of lines in the text file.Utilities.LineCatalog.Line
getLineFromOffset(int offset)
Retrieves a single catalog Line for the line containing the requested offset character.java.util.ListIterator<Utilities.LineCatalog.Line>
getLineIterator()
Get an iterator over the cataloged record Lines.int
getWarningCount()
Get the number of warnings issuedduring the cataloging.java.lang.String
toString()
Displays all lines of text with all Line information for each line.
-
-
-
Constructor Detail
-
LineCatalog
public LineCatalog(java.lang.String inputString) throws java.lang.IllegalArgumentException
Constructor- Parameters:
inputString
- the text whose lines are to be cataloged as a String.- Throws:
java.lang.IllegalArgumentException
- thrown if the input string is null or empty.
-
LineCatalog
public LineCatalog(char[] inputArray) throws java.lang.IllegalArgumentException
Constructor- Parameters:
inputArray
- the text whose lines are to be cataloged as a character array.- Throws:
java.lang.IllegalArgumentException
- thrown if the input string is null or empty.
-
-
Method Detail
-
toString
public java.lang.String toString()
Displays all lines of text with all Line information for each line.- Overrides:
toString
in classjava.lang.Object
- Returns:
- the display as a single String.
-
getLine
public Utilities.LineCatalog.Line getLine(int lineno)
Retrieves a single catalog Line by line number.- Parameters:
lineno
- the number (1-based) of the line to retrieve.- Returns:
- the catalog Line record.
-
getLineFromOffset
public Utilities.LineCatalog.Line getLineFromOffset(int offset)
Retrieves a single catalog Line for the line containing the requested offset character.- Parameters:
offset
- the offset of the first text character to find the line of.- Returns:
- the catalog record Line.
-
getErrorCount
public int getErrorCount()
Get the number of errors encountered during the cataloging.- Returns:
- the number of errors.
-
getWarningCount
public int getWarningCount()
Get the number of warnings issuedduring the cataloging.- Returns:
- the number of warnings.
-
displayErrors
public void displayErrors(java.io.PrintStream out)
Displays all errors encountered during the cataloging, if any.- Parameters:
out
- the output device to display on.
-
displayWarnings
public void displayWarnings(java.io.PrintStream out)
Displays all warnings issued during the cataloging, if any.- Parameters:
out
- the output device to display on.
-
getLineCount
public int getLineCount()
Get the number of lines in the text file.- Returns:
- the number of lines
-
getLineIterator
public java.util.ListIterator<Utilities.LineCatalog.Line> getLineIterator()
Get an iterator over the cataloged record Lines.- Returns:
- the iterator.
-
clear
public void clear()
Clears the catalog of all lines. Clears the list of errors and warnings.
-
-