Copyright (C) 2003,2004 dr. Cristiano Sadun

org.sadun.text.ffp
Class ConstantFoundInLineCondition

java.lang.Object
  extended byorg.sadun.text.ffp.ConstantFoundInLineCondition
All Implemented Interfaces:
FlatFileParser.Condition

public class ConstantFoundInLineCondition
extends java.lang.Object
implements FlatFileParser.Condition

A condition that looks for a matching constant into a specific physical line.

Author:
Cristiano Sadun

Constructor Summary
ConstantFoundInLineCondition(int physicalLine, LineFormat format)
          Create a condition which will look at the value of the first constant field in the given physical line of the given LineFormatobject.
ConstantFoundInLineCondition(int physicalLine, LineFormat format, int n)
          Create a condition which will look at the value of the nth field of the given physical line in the given LineFormatobject.
ConstantFoundInLineCondition(int physicalLine, java.lang.String constant, int startPosition)
          Create a condition which will look for the given constant at the given position of the given physical line in the file.
ConstantFoundInLineCondition(LineFormat format)
          Create a condition which will look at the value of the first constant field of in the given LineFormatobject.
ConstantFoundInLineCondition(LineFormat format, int n)
          Create a condition which will look at the value of the nth field in the given LineFormatobject.
ConstantFoundInLineCondition(java.lang.String constant, int startPosition)
          Create a condition which will look for the given constant at the given position of the next line in the file.
 
Method Summary
 boolean holds(int logicalLineCount, int physicalLineCount, FlatFileParser.LineReader reader)
          Return true if a desired logical condition holds.
protected  java.lang.String readPhysicalLines(FlatFileParser.LineReader reader, int n)
          Read n physical lines and returns the n-th.
 java.lang.String toString()
          Return a human-readable description of the condition.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(int physicalLine,
                                    java.lang.String constant,
                                    int startPosition)
Create a condition which will look for the given constant at the given position of the given physical line in the file.

Parameters:
physicalLine - the physical line in which the constant is to be looked for
constant - the constant to look for
startPosition - the position in the physical line where to look for the constant

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(java.lang.String constant,
                                    int startPosition)
Create a condition which will look for the given constant at the given position of the next line in the file.

Parameters:
constant - the constant to look for
startPosition - the position in the line where to look for the constant

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(int physicalLine,
                                    LineFormat format,
                                    int n)
Create a condition which will look at the value of the nth field of the given physical line in the given LineFormatobject.

The field must have type Type.CONSTANT.

This constructor is useful when a LineFormathas already been defined with the constant value to be looked for by this condition.

Parameters:
format - the LineFormatfrom which to get the constant value
physicalLine - the physical line of the field (starting with 1)
n - the number of the field (starting with 1)

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(LineFormat format,
                                    int n)
Create a condition which will look at the value of the nth field in the given LineFormatobject.

The field must have type Type.CONSTANT.

This constructor is useful when a LineFormathas already been defined with the constant value to be looked for by this condition.

Parameters:
format - the LineFormatfrom which to get the constant value
n - the number of the field (starting with 1)

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(int physicalLine,
                                    LineFormat format)
Create a condition which will look at the value of the first constant field in the given physical line of the given LineFormatobject.

The format must have at least one field defined as type Type.CONSTANT.

This constructor is useful when a LineFormathas already been defined with the constant value to be looked for by this condition.

Parameters:
format - the LineFormatfrom which to get the constant value
physicalLine - the physical line of the field (starting with 1)
Throws:
java.lang.IllegalArgumentException - if the given format does not have any constantfield.

ConstantFoundInLineCondition

public ConstantFoundInLineCondition(LineFormat format)
Create a condition which will look at the value of the first constant field of in the given LineFormatobject.

The format must have at least one field defined as type Type.CONSTANT.

This constructor is useful when a LineFormathas already been defined with the constant value to be looked for by this condition.

Parameters:
format - the LineFormatfrom which to get the constant value
Throws:
java.lang.IllegalArgumentException - if the given format does not have any constantfield.
Method Detail

holds

public boolean holds(int logicalLineCount,
                     int physicalLineCount,
                     FlatFileParser.LineReader reader)
              throws java.io.IOException
Description copied from interface: FlatFileParser.Condition
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.

Specified by:
holds in interface FlatFileParser.Condition
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

readPhysicalLines

protected java.lang.String readPhysicalLines(FlatFileParser.LineReader reader,
                                             int n)
                                      throws java.io.IOException
Read n physical lines and returns the n-th.

If no enough lines exist, null is returned.

Parameters:
reader -
n -
Returns:
Throws:
java.io.IOException

toString

public java.lang.String toString()
Description copied from interface: FlatFileParser.Condition
Return a human-readable description of the condition.

Specified by:
toString in interface FlatFileParser.Condition

Copyright (C) 2003,2004 dr. Cristiano Sadun