Copyright (C) 2003,2004 dr. Cristiano Sadun

org.sadun.text.ffp
Class MatchingRegexpInLineCondition

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

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

A condition that checks a regular expression in a physical line.

Version:
1.0
Author:
Cristiano Sadun

Constructor Summary
MatchingRegexpInLineCondition(int physicalLine, java.lang.String regexp, int startPosition)
          Create a condition which will look for the given constant at the given position of the given physical line in the file.
MatchingRegexpInLineCondition(int physicalLine, java.lang.String regexp, 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 LineFormat object.
MatchingRegexpInLineCondition(java.lang.String regexp, int startPosition)
          Create a condition which will look for the given regexp at the given position of the next line in the file.
MatchingRegexpInLineCondition(java.lang.String regexp, 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 LineFormat object.
 
Method Summary
 boolean holds(int logicalLineCount, int physicalLineCount, FlatFileParser.LineReader reader)
          Attempt to match the regular expression and line position provided at construction to the physical line.
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

MatchingRegexpInLineCondition

public MatchingRegexpInLineCondition(int physicalLine,
                                     java.lang.String regexp,
                                     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
regexp - the regular expression to match
startPosition - the position in the physical line where to look for the constant

MatchingRegexpInLineCondition

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

Parameters:
regexp - the regular expression to match
startPosition - the position in the line where to look for the regexp

MatchingRegexpInLineCondition

public MatchingRegexpInLineCondition(int physicalLine,
                                     java.lang.String regexp,
                                     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 LineFormat object.

The field must have type Type.CONSTANT.

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

Parameters:
format - the LineFormat from which to get the regexp value
regexp - the regular expression to match
physicalLine - the physical line of the field (starting with 1)
n - the number of the field (starting with 1)

MatchingRegexpInLineCondition

public MatchingRegexpInLineCondition(java.lang.String regexp,
                                     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 LineFormat object.

The field must have type Type.CONSTANT.

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

Parameters:
format - the LineFormat from which to get the regexp value
regexp - the regular expression to match
n - the number of the field (starting with 1)
Method Detail

holds

public boolean holds(int logicalLineCount,
                     int physicalLineCount,
                     FlatFileParser.LineReader reader)
              throws java.io.IOException
Attempt to match the regular expression and line position provided at construction to the physical line.

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
See Also:
FlatFileParser.Condition.holds(int, int, org.sadun.text.ffp.FlatFileParser.LineReader)

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