Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


oracle.javatools.parser.util
Class KeywordTable

java.lang.Object
  extended by oracle.javatools.parser.util.KeywordTable


public final class KeywordTable
extends java.lang.Object

The KeywordTable utility class is a stripped down hash table implementation with a couple assumptions:

See Also:
Lexer

Constructor Summary
KeywordTable(int numKeywords)
          Constructs a new empty KeywordTable for the given size (number of keywords.)

 

Method Summary
 void addKeyword(java.lang.String keyword, int token)
          Adds the given keywords/token pair to the keyword table.
static int computeHash(char[] keyword)
          Utility routine to calculate the hash value of a string used for this keyword table.
static int computeInsensitiveHash(char[] keyword)
          Utility routine to calculate the (case insensitive) hash value of a string used for this keyword table.
static int computeInsensitivePartialHash(char nextChar, int lastHash)
          Utility routine to calculate the (case insensitive) hash value of a keyword character by character (from left to right).
static int computePartialHash(char nextChar, int lastHash)
          Utility routine to calculate the hash value of a keyword character by character (from left to right).
 int lookupKeyword(ReadTextBuffer buffer, int startOffset, int endOffset, int precomputedHash)
          Lookup the given keyword marked by the given start and end offset in the ReadTextBuffer, and return the matching token value, or Lexer.TK_NOT_FOUND if there is no such keyword in the table.
 void setCaseSensitivity(boolean isCaseSensitive)
          Sets the case sensitivity of the table as indiciated by client.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

 

Constructor Detail

KeywordTable

public KeywordTable(int numKeywords)
Constructs a new empty KeywordTable for the given size (number of keywords.)
Parameters:
numKeywords - number of expected keywords in table

Method Detail

setCaseSensitivity

public void setCaseSensitivity(boolean isCaseSensitive)
Sets the case sensitivity of the table as indiciated by client.
Parameters:
isCaseSensitive - true to perform case-sensitive lookups

addKeyword

public void addKeyword(java.lang.String keyword,
                       int token)
Adds the given keywords/token pair to the keyword table.
Parameters:
keyword - the keyword to use as a key to the hash table
token - the token value to use as the value

lookupKeyword

public int lookupKeyword(ReadTextBuffer buffer,
                         int startOffset,
                         int endOffset,
                         int precomputedHash)
Lookup the given keyword marked by the given start and end offset in the ReadTextBuffer, and return the matching token value, or Lexer.TK_NOT_FOUND if there is no such keyword in the table.
Parameters:
buffer - the TextBuffer of the keyword to look up
startOffset - the starting offset of the keyword in the buffer
endOffset - the ending offset of the keyword in the buffer
Returns:
the token value corresponding to the keyword or Lexer.TK_NOT_FOUND if the keyword is not found.

computeHash

public static int computeHash(char[] keyword)
Utility routine to calculate the hash value of a string used for this keyword table.
Parameters:
keyword - the keyword to hash
Returns:
the hash value

computeInsensitiveHash

public static int computeInsensitiveHash(char[] keyword)
Utility routine to calculate the (case insensitive) hash value of a string used for this keyword table.
Parameters:
keyword - the keyword to hash
Returns:
the hash value

computePartialHash

public static int computePartialHash(char nextChar,
                                     int lastHash)
Utility routine to calculate the hash value of a keyword character by character (from left to right). This is useful so that as we are looking for the end of the identifier in the Lexer, we can be calculating the hash value as we go.
Parameters:
nextChar - the next character in the sequence
lastHash - the last last value computed
Returns:
the new partial hash value

computeInsensitivePartialHash

public static int computeInsensitivePartialHash(char nextChar,
                                                int lastHash)
Utility routine to calculate the (case insensitive) hash value of a keyword character by character (from left to right). This is useful so that as we are looking for the end of the identifier in the Lexer, we can be calculating the hash value as we go.
Parameters:
nextChar - the next character in the sequence
lastHash - the last last value computed
Returns:
the new partial hash value

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.2.0)

E17493-03


Copyright © 1997, 2012, Oracle. All rights reserved.