Copyright (C) 2003,2004 dr. Cristiano Sadun

org.sadun.text.ffp
Interface FlatFileParser.Condition

All Known Implementing Classes:
AndCondition, ConstantFoundInLineCondition, ConstantLineCondition, CountCondition, MatchingRegexpInLineCondition, NotCondition, NullCondition, OrCondition
Enclosing interface:
FlatFileParser

public static interface FlatFileParser.Condition

An object implementing this interface can decide whether or not the physical line currently available for reading match or not a certain condition, in the FlatFileParser.Condition#holds(int, int, LineReader) method. A Condition is usually associated to a LineFormat in a FlatFileParser object.

The Condition object can read as many physical lines as required from the file before deciding whether or not the condition holds. It can check things like whether the current line number is lower than a certain number, or if two lines are available and the second contains a certain constant at a certain position, etc.

For example, if a file has ten lines of header with a certain format, followed by any number of lines with a second format, code like the following is a possible Condition identifying header lines.

  public boolean holds(int logicalLineCount, int physicalLineCount, LineReader reader) throws IOException {
   // Check if we are in the file header
   return logicalLineCount < 10;
  }
 

Some implementations are provided by the library for common types of conditions.

Author:
Cristiano Sadun

Method Summary
 boolean holds(int logicalLineCount, int physicalLineCount, FlatFileParser.LineReader reader)
          Return true if a desired logical condition holds.
 java.lang.String toString()
          Return a human-readable description of the condition.
 

Method Detail

holds

public boolean holds(int logicalLineCount,
                     int physicalLineCount,
                     FlatFileParser.LineReader reader)
              throws java.io.IOException
Return true if a desired logical condition holds. The condition can regard the next lines available in the file (accessible by the reader parameter) or the number of physical or logical lines read so far.

Note that the implementation can use the reader object to read as many lines as necessary to verify if a certain condition holds - but should return false unless an IOException due to real i/o problems (and not, for example, that not enough lines exist on the file and therefore EOF is reached) is raised.

Parameters:
logicalLineCount - the logical lines read so far
physicalLineCount - the physical lines read so far
reader - an object allowing to read lines on the file
Returns:
true if the conditions hold, false otherwise.
Throws:
java.io.IOException - if a I/O problem arises when reading lines

toString

public java.lang.String toString()
Return a human-readable description of the condition.

Returns:
a human-readable description of the condition.

Copyright (C) 2003,2004 dr. Cristiano Sadun