ru.biosoft.access
Class IndexTable

java.lang.Object
  extended byjava.util.Dictionary
      extended byjava.util.Hashtable
          extended byru.biosoft.access.IndexTable
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable

public class IndexTable
extends java.util.Hashtable

IndexTable extention of hash table for work with database indexes. Build index file for flat file and then use them.

Version:
1.0
Author:
DevelopmentOnTheEdge
See Also:
Serialized Form
Pendung:
temporary implementation (speed up), urgent This class should be removed.

Field Summary
protected static org.apache.log4j.Category cat
          log
protected  java.lang.String delimiters
          Delimiter characters.
static java.lang.String ENTRY_DELIMITERS_PROPERTY
           
static java.lang.String ENTRY_END_PROPERTY
           
static java.lang.String ENTRY_ID_PROPERTY
           
static java.lang.String ENTRY_START_PROPERTY
           
static java.lang.String INDEX_SUFFIX
           
protected  java.io.RandomAccessFile indexFile
          Index file.
protected  java.io.File indexFileName
          Name of index file.
protected  java.util.Vector indexList
          The vector of sorted alphabetically field values.
protected  java.lang.String startKey
          Name of indexed startKey.
 
Constructor Summary
IndexTable(java.io.RandomAccessFile f, java.lang.String startKey, java.util.Properties properties)
          Creates a IndexTable, that contains indexes for entry searching by specified line (startKey).
 
Method Summary
protected  void addKey(java.lang.String key)
          Add key to the index list.
 void close()
           
protected  java.lang.String extractKey(java.lang.String data, java.lang.String start, java.lang.String delimiters)
          Parse data and extract key from it.
protected  void finalize()
          Free resources.
 ru.biosoft.access.IndexTable.Index get(java.lang.String key)
          Gets the index value associated with index key.
 ru.biosoft.access.IndexTable.Index put(java.io.RandomAccessFile f, Entry entry)
          Put new entry to the file and puts the corresponding entry index table.
 ru.biosoft.access.IndexTable.Index put(java.io.RandomAccessFile f, java.lang.String entry)
          Put new entry to the file and puts the corresponding entry index table.
 void putIndex(java.lang.String key, ru.biosoft.access.IndexTable.Index value)
          Put new index into index table.
 void removeIndex(java.lang.String key)
          Remove the key from the index table.
protected  void writeIndex(java.lang.String key, ru.biosoft.access.IndexTable.Index ind)
           
protected  void writeIndex(java.lang.String key, int from, int len)
          Write the index to file.
 
Methods inherited from class java.util.Hashtable
clear, clone, contains, containsKey, containsValue, elements, entrySet, equals, get, hashCode, isEmpty, keys, keySet, put, putAll, rehash, remove, size, toString, values
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INDEX_SUFFIX

public static final java.lang.String INDEX_SUFFIX
See Also:
Constant Field Values

ENTRY_DELIMITERS_PROPERTY

public static final java.lang.String ENTRY_DELIMITERS_PROPERTY
See Also:
Constant Field Values

ENTRY_START_PROPERTY

public static final java.lang.String ENTRY_START_PROPERTY
See Also:
Constant Field Values

ENTRY_ID_PROPERTY

public static final java.lang.String ENTRY_ID_PROPERTY
See Also:
Constant Field Values

ENTRY_END_PROPERTY

public static final java.lang.String ENTRY_END_PROPERTY
See Also:
Constant Field Values

delimiters

protected java.lang.String delimiters
Delimiter characters.

Default value is: ";\t\r\n".


startKey

protected java.lang.String startKey
Name of indexed startKey.


indexList

protected java.util.Vector indexList
The vector of sorted alphabetically field values.


indexFile

protected java.io.RandomAccessFile indexFile
Index file.


indexFileName

protected java.io.File indexFileName
Name of index file.


cat

protected static org.apache.log4j.Category cat
log

Constructor Detail

IndexTable

public IndexTable(java.io.RandomAccessFile f,
                  java.lang.String startKey,
                  java.util.Properties properties)
           throws java.lang.Exception
Creates a IndexTable, that contains indexes for entry searching by specified line (startKey). Also puts index in sorted array of strings.

Note. It is a very simple version. Only one index per entry is created. The index value is the first substring in the first approprate entry line (startKey).

Parameters:
f - database file
startKey - name of line (startKey) for indexation.
properties - data to turn in entry parsing.
Method Detail

writeIndex

protected void writeIndex(java.lang.String key,
                          int from,
                          int len)
                   throws java.io.IOException
Write the index to file.

Parameters:
key - the key
Throws:
java.io.IOException

writeIndex

protected void writeIndex(java.lang.String key,
                          ru.biosoft.access.IndexTable.Index ind)
                   throws java.io.IOException
Throws:
java.io.IOException

finalize

protected void finalize()
                 throws java.lang.Throwable
Free resources. Close index file.

Throws:
java.lang.Throwable - If error occured.
See Also:
close()

addKey

protected void addKey(java.lang.String key)
Add key to the index list.


get

public ru.biosoft.access.IndexTable.Index get(java.lang.String key)
Gets the index value associated with index key.

Parameters:
key - the specified index key
Returns:
the index value or null if the key is not defined in the index table.

extractKey

protected java.lang.String extractKey(java.lang.String data,
                                      java.lang.String start,
                                      java.lang.String delimiters)
                               throws java.lang.Exception
Parse data and extract key from it.

Parameters:
data - Text with key.
start - Start tag after which key is placed.
delimiters - Set of symbols that not contained in the key.
Returns:
Key of the entry.
Throws:
java.lang.Exception

putIndex

public void putIndex(java.lang.String key,
                     ru.biosoft.access.IndexTable.Index value)
              throws java.io.IOException
Put new index into index table.

Parameters:
key - index key.
value - index value.
Returns:
the old value of the key, or null if it did not have one.
Throws:
java.io.IOException

put

public ru.biosoft.access.IndexTable.Index put(java.io.RandomAccessFile f,
                                              Entry entry)
                                       throws java.lang.Exception
Put new entry to the file and puts the corresponding entry index table.

Parameters:
f - the database file
entry - database entry that will be added
Returns:
the new entry index
Throws:
java.lang.Exception

put

public ru.biosoft.access.IndexTable.Index put(java.io.RandomAccessFile f,
                                              java.lang.String entry)
                                       throws java.lang.Exception
Put new entry to the file and puts the corresponding entry index table.

Parameters:
f - the database file
entry - database entry that will be added
Returns:
the new entry index
Throws:
java.lang.Exception

removeIndex

public void removeIndex(java.lang.String key)
                 throws java.io.IOException
Remove the key from the index table.

Parameters:
key - key to be removed.
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2001-2003 Biosof.Ru. All Rights Reserved.