org.cdlib.xtf.util
Class CharMap

Object
  extended by CharMap

public class CharMap
extends Object

Maintains an in-memory, one-to-one mapping from characters in one set to characters in another. The list is read from a disk file, which may be sorted or unsorted. The format of file entries should be one pair per line, separated by a bar ("|") character. The first word is considered the "key", the second is the "value". Each should be a four-digit hex number representing a Unicode code point. For speed, an in-memory cache of recently mapped words is maintained.


Field Summary
private  FastCache cache
          Keep a cache of lookups performed to-date
private static int CACHE_SIZE
          How many recent mappings to maintain
private  char[] map
          The mapping of chars.
private static char NULL_CHAR
          Special character to denote null list
private static int SUPP_HASH_SIZE
          Size of supplimental mapping of chars... typically there are few
private  IntHash supplementalCharsMap
          Supplemental mapping of characters after the first
 
Constructor Summary
CharMap(File f)
          Construct a char map by reading in a file.
CharMap(InputStream s)
          Construct a char map by reading from an InputStream.
 
Method Summary
 String mapWord(String word)
          Map the characters in a word and return the mapped resulting word, or null if no mappings found.
private  void readFile(BufferedReader reader)
          Read in the contents of a char file.
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private char[] map
The mapping of chars.


NULL_CHAR

private static final char NULL_CHAR
Special character to denote null list

See Also:
Constant Field Values

SUPP_HASH_SIZE

private static final int SUPP_HASH_SIZE
Size of supplimental mapping of chars... typically there are few

See Also:
Constant Field Values

supplementalCharsMap

private IntHash supplementalCharsMap
Supplemental mapping of characters after the first


CACHE_SIZE

private static final int CACHE_SIZE
How many recent mappings to maintain

See Also:
Constant Field Values

cache

private FastCache cache
Keep a cache of lookups performed to-date

Constructor Detail

CharMap

public CharMap(File f)
        throws IOException
Construct a char map by reading in a file.

Throws:
IOException

CharMap

public CharMap(InputStream s)
        throws IOException
Construct a char map by reading from an InputStream.

Throws:
IOException
Method Detail

mapWord

public String mapWord(String word)
Map the characters in a word and return the mapped resulting word, or null if no mappings found.


readFile

private void readFile(BufferedReader reader)
               throws IOException
Read in the contents of a char file. The file need not be in sorted order.

Parameters:
reader - Reader to get the data from
Throws:
IOException