mirror of https://github.com/apache/lucene.git
hide implementation detail of pcmList
git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@714230 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bac3536b2e
commit
51444a5ac6
|
@ -28,28 +28,36 @@ import java.util.List;
|
|||
*/
|
||||
public abstract class BaseCharFilter extends CharFilter {
|
||||
|
||||
protected List<PosCorrectMap> pcmList;
|
||||
private List<PosCorrectMap> pcmList;
|
||||
|
||||
public BaseCharFilter( CharStream in ){
|
||||
super(in);
|
||||
pcmList = new ArrayList<PosCorrectMap>();
|
||||
}
|
||||
|
||||
protected int correctPosition( int currentPos ){
|
||||
if( pcmList.isEmpty() ) return currentPos;
|
||||
if( pcmList == null || pcmList.isEmpty() ) return currentPos;
|
||||
for( int i = pcmList.size() - 1; i >= 0; i-- ){
|
||||
if( currentPos >= pcmList.get( i ).pos )
|
||||
return currentPos + pcmList.get( i ).cumulativeDiff;
|
||||
}
|
||||
return currentPos;
|
||||
}
|
||||
|
||||
protected int getLastCumulativeDiff(){
|
||||
return pcmList == null || pcmList.isEmpty() ? 0 : pcmList.get( pcmList.size() - 1 ).cumulativeDiff;
|
||||
}
|
||||
|
||||
protected void addPosCorrectMap( int pos, int cumulativeDiff ){
|
||||
if( pcmList == null ) pcmList = new ArrayList<PosCorrectMap>();
|
||||
pcmList.add( new PosCorrectMap( pos, cumulativeDiff ) );
|
||||
}
|
||||
|
||||
protected static class PosCorrectMap {
|
||||
static class PosCorrectMap {
|
||||
|
||||
protected int pos;
|
||||
protected int cumulativeDiff;
|
||||
int pos;
|
||||
int cumulativeDiff;
|
||||
|
||||
public PosCorrectMap( int pos, int cumulativeDiff ){
|
||||
PosCorrectMap( int pos, int cumulativeDiff ){
|
||||
this.pos = pos;
|
||||
this.cumulativeDiff = cumulativeDiff;
|
||||
}
|
||||
|
|
|
@ -54,14 +54,13 @@ public class MappingCharFilter extends BaseCharFilter {
|
|||
replacement = result.normStr;
|
||||
charPointer = 0;
|
||||
if( result.diff != 0 ){
|
||||
int prevCumulativeDiff = pcmList.isEmpty() ? 0 :
|
||||
pcmList.get( pcmList.size() - 1 ).cumulativeDiff;
|
||||
int prevCumulativeDiff = getLastCumulativeDiff();
|
||||
if( result.diff < 0 ){
|
||||
for( int i = 0; i < -result.diff ; i++ )
|
||||
pcmList.add( new PosCorrectMap( nextCharCounter + i - prevCumulativeDiff, prevCumulativeDiff - 1 - i ) );
|
||||
addPosCorrectMap( nextCharCounter + i - prevCumulativeDiff, prevCumulativeDiff - 1 - i );
|
||||
}
|
||||
else{
|
||||
pcmList.add( new PosCorrectMap( nextCharCounter - result.diff - prevCumulativeDiff, prevCumulativeDiff + result.diff ) );
|
||||
addPosCorrectMap( nextCharCounter - result.diff - prevCumulativeDiff, prevCumulativeDiff + result.diff ) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue