de.hunsicker.jalopy.swing.syntax
Class KeywordMap

java.lang.Object
  |
  +--de.hunsicker.jalopy.swing.syntax.KeywordMap

public final class KeywordMap
extends java.lang.Object

A KeywordMap is similar to a hashtable in that it maps keys to values. However, the `keys' are Swing segments. This allows lookups of text substrings without the overhead of creating a new string object.

This class is used by CTokenMarker to map keywords to ids.

Version:
$Id: KeywordMap.java,v 1.1 2002/11/11 22:08:35 marcohu Exp $
Author:
Slava Pestov, Mike Dillon

Field Summary
protected  int mapLength
          DOCUMENT ME!
 
Constructor Summary
KeywordMap(boolean ignoreCase)
          Creates a new KeywordMap.
KeywordMap(boolean ignoreCase, int mapLength)
          Creates a new KeywordMap.
 
Method Summary
 void add(java.lang.String keyword, byte id)
          Adds a key-value mapping.
 boolean getIgnoreCase()
          Returns true if the keyword map is set to be case insensitive, false otherwise.
protected  int getSegmentMapKey(javax.swing.text.Segment s, int off, int len)
          DOCUMENT ME!
protected  int getStringMapKey(java.lang.String s)
          DOCUMENT ME!
 byte lookup(javax.swing.text.Segment text, int offset, int length)
          Looks up a key.
 void setIgnoreCase(boolean ignoreCase)
          Sets if the keyword map should be case insensitive.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapLength

protected int mapLength
DOCUMENT ME!

Constructor Detail

KeywordMap

public KeywordMap(boolean ignoreCase)
Creates a new KeywordMap.

Parameters:
ignoreCase - True if keys are case insensitive

KeywordMap

public KeywordMap(boolean ignoreCase,
                  int mapLength)
Creates a new KeywordMap.

Parameters:
ignoreCase - True if the keys are case insensitive
mapLength - The number of `buckets' to create. A value of 52 will give good performance for most maps.
Method Detail

setIgnoreCase

public void setIgnoreCase(boolean ignoreCase)
Sets if the keyword map should be case insensitive.

Parameters:
ignoreCase - True if the keyword map should be case insensitive, false otherwise

getIgnoreCase

public boolean getIgnoreCase()
Returns true if the keyword map is set to be case insensitive, false otherwise.

Returns:
DOCUMENT ME!

add

public void add(java.lang.String keyword,
                byte id)
Adds a key-value mapping.

Parameters:
keyword - The key
id - The value

lookup

public byte lookup(javax.swing.text.Segment text,
                   int offset,
                   int length)
Looks up a key.

Parameters:
text - The text segment
offset - The offset of the substring within the text segment
length - The length of the substring
Returns:
DOCUMENT ME!

getSegmentMapKey

protected int getSegmentMapKey(javax.swing.text.Segment s,
                               int off,
                               int len)
DOCUMENT ME!

Parameters:
s - DOCUMENT ME!
off - DOCUMENT ME!
len - DOCUMENT ME!
Returns:
DOCUMENT ME!

getStringMapKey

protected int getStringMapKey(java.lang.String s)
DOCUMENT ME!

Parameters:
s - DOCUMENT ME!
Returns:
DOCUMENT ME!


Copyright © 1997-2005 Jalopy. All Rights Reserved.