javatools.parsers
Class PositionTracker.ForwardPositionTracker

java.lang.Object
  extended by javatools.parsers.PositionTracker.ForwardPositionTracker
Enclosing class:
PositionTracker

public static class PositionTracker.ForwardPositionTracker
extends java.lang.Object

forward position change tracking - keeping track of several rounds of text modifications allowing to trace a position in the original text along the modifications to the corresp. position in the modified text after each round (one round=consecutive changes along the text) you need to call closeRun() before submitting more position changes from a new round, i.e. whenever you passed the string to be modified once call closeRun() before starting to run over the string again with more replacements REMARK: NOT TESTED WITH MORE THAN ONE ROUND! may be ERRORNOUS with multiple rounds -> use with care (works with a single round though)

Author:
smetzger

Constructor Summary
PositionTracker.ForwardPositionTracker()
           
 
Method Summary
 void addPositionChange(int pos, int modifier)
           
 void closeRun()
          Closes the current changing run by Merging new position changes into the existing position change map Do this every time you ran once over the text making changes to be tracked
 boolean hasBeenCutAway(java.lang.Integer pos)
          tells whether a position in the original stream has been cut away by some change operation, such that translating it usually would make not to much sense
 java.lang.Integer translatePosition(java.lang.Integer pos)
           
 java.lang.Integer translatePositionExactly(java.lang.Integer pos)
          also handles positions inside text parts that have been cut out properly TODO: current version ONLY WORKS SECURELY WHEN THERE IS ONLY ONE POSITION CHANGE RUN WITHOUT OVERLAPPING CHANGES! as soon as there are more than one change runs, or changes that overlap, we would need to check all following changes instead of only the next one
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PositionTracker.ForwardPositionTracker

public PositionTracker.ForwardPositionTracker()
Method Detail

addPositionChange

public void addPositionChange(int pos,
                              int modifier)

closeRun

public void closeRun()
Closes the current changing run by Merging new position changes into the existing position change map Do this every time you ran once over the text making changes to be tracked


hasBeenCutAway

public boolean hasBeenCutAway(java.lang.Integer pos)
tells whether a position in the original stream has been cut away by some change operation, such that translating it usually would make not to much sense

Returns:
true, iff the given position has been cut away, false otherwise (i.e. false if it should be mappable) TODO: current version ONLY WORKS SECURELY WHEN THERE IS ONLY ONE POSITION CHANGE RUN WITHOUT OVERLAPPING CHANGES! as soon as there are more than one change runs, or changes that overlap, we would need to check all following changes instead of only the next one

translatePosition

public java.lang.Integer translatePosition(java.lang.Integer pos)

translatePositionExactly

public java.lang.Integer translatePositionExactly(java.lang.Integer pos)
also handles positions inside text parts that have been cut out properly TODO: current version ONLY WORKS SECURELY WHEN THERE IS ONLY ONE POSITION CHANGE RUN WITHOUT OVERLAPPING CHANGES! as soon as there are more than one change runs, or changes that overlap, we would need to check all following changes instead of only the next one