org.jtr.transliterate
Class CharacterList

java.lang.Object
  |
  +--org.jtr.transliterate.CharacterList

public final class CharacterList
extends java.lang.Object

Holds an ordered list of characters and character ranges. This is the basic data structure for finding transliterations to perform.

Usage:

This class is normally created and populated directly from the CharacterParser class. CharacterList objects are immutable, so no additional patterns can be added once the object has been constructed. This allows CharacterList objects to be used by multiple threads simultaneously.

Once a character list has been created, it will normally be passed into a CharacterReplacer constructor for processing. However, character lists may also be cached, since they hold no state information during the parsing itself. This would remove compile-time costs of creating the list when performance is critical.

Version:
$Id: CharacterList.java,v 1.7 2005/02/16 12:42:38 run2000 Exp $
Author:
Nicholas Cull

Constructor Summary
CharacterList()
          Creates an empty CharacterList
CharacterList(java.util.List cCharList)
          Creates new CharacterList, using the given list of ListEntry objects.
 
Method Summary
 int findCharAtPosition(int nPosition, boolean bDeleteUnreplaceables)
          Finds the character corresponding to the given position in the list.
 int getMatch(char nChar, boolean bComplement)
          Determines whether a given character exists in the list.
 int size()
          Determines the total number of characters in the list—not just the number of entries in the underlying array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CharacterList

public CharacterList()
Creates an empty CharacterList

CharacterList

public CharacterList(java.util.List cCharList)
Creates new CharacterList, using the given list of ListEntry objects.
Parameters:
cCharList - a List of ListEntry objects to be stored in the array
Throws:
NullPointerException - if cCharList is null
Method Detail

getMatch

public int getMatch(char nChar,
                    boolean bComplement)
Determines whether a given character exists in the list. If it does, returns the first occurrence of that character in the list.
Parameters:
nChar - the character to be matched
bComplement - determines behaviour when the COMPLEMENT_MASK flag is set—if false, the list is scanned normally, otherwise the complement of the list is used
Returns:
the logical position in the list where the character was found, or -1 if the character could not be found

findCharAtPosition

public int findCharAtPosition(int nPosition,
                              boolean bDeleteUnreplaceables)
Finds the character corresponding to the given position in the list.
Parameters:
nPosition - the position where the resulting character should be found in the list
bDeleteUnreplaceables - determines behaviour when the DELETE_UNREPLACEABLES_MASK is set—if false, the last character in the list will be returned, otherwise -1 is returned
Returns:
the character corresponding to the position in the list, or -1 if the character could not be found

size

public int size()
Determines the total number of characters in the list—not just the number of entries in the underlying array.
Returns:
the total number of characters in the pattern