org.apache.jackrabbit.core.persistence.util
Class HashMapIndex

java.lang.Object
  extended by org.apache.jackrabbit.core.persistence.util.HashMapIndex
All Implemented Interfaces:
StringIndex
Direct Known Subclasses:
FileBasedIndex

public class HashMapIndex
extends Object
implements StringIndex

Implements a StringIndex that is based on a hashmap. Subclasses can override the protected load() and save() methods to implement persistent storage of the string index.

This class is thread-safe.


Field Summary
protected  HashMap<Integer,String> indexToString
          holds the index-to-string lookups.
protected  HashMap<String,Integer> stringToIndex
          holds the string-to-index lookups.
 
Constructor Summary
HashMapIndex()
           
 
Method Summary
 String indexToString(int i)
          Returns the string for a given index.
protected  void load()
          Loads the lookup table.
protected  void save()
          Saves the lookup table.
 int stringToIndex(String nsUri)
          Returns the index for a given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

stringToIndex

protected final HashMap<String,Integer> stringToIndex
holds the string-to-index lookups.


indexToString

protected final HashMap<Integer,String> indexToString
holds the index-to-string lookups.

Constructor Detail

HashMapIndex

public HashMapIndex()
Method Detail

load

protected void load()
Loads the lookup table.


save

protected void save()
Saves the lookup table.


stringToIndex

public int stringToIndex(String nsUri)
Returns the index for a given string. If the given string is not already indexed, the implementation can either automatically index it or throw an exception. This implementation reloads the table from the resource if a lookup fails and if the resource was modified since.

Specified by:
stringToIndex in interface StringIndex
Parameters:
nsUri - the indexed (or to be indexed) string
Returns:
index of the string

indexToString

public String indexToString(int i)
Returns the string for a given index. This implementation reloads the table from the resource if a lookup fails and if the resource was modified since.

Specified by:
indexToString in interface StringIndex
Parameters:
i - index of a string
Returns:
the indexed string


Copyright © 2004-2010 The Apache Software Foundation. All Rights Reserved.