org.openstreetmap.osmosis.core.store
Class IndexStoreReader<K,T extends IndexElement<K>>

java.lang.Object
  extended by org.openstreetmap.osmosis.core.store.IndexStoreReader<K,T>
Type Parameters:
K - The index key type.
T - The object type being stored.
All Implemented Interfaces:
Releasable

public class IndexStoreReader<K,T extends IndexElement<K>>
extends java.lang.Object
implements Releasable

Provides read-only access to an index store. Each thread accessing the object store must create its own reader. The reader maintains all references to heavyweight resources such as file handles used to access the store eliminating the need for objects such as object iterators to be cleaned up explicitly.

Author:
Brett Henderson

Constructor Summary
IndexStoreReader(RandomAccessObjectStoreReader<T> indexStoreReader, java.util.Comparator<K> ordering)
          Creates a new instance.
 
Method Summary
 T get(K key)
          Returns the index element identified by id.
 java.util.Iterator<T> getRange(K beginKey, K endKey)
          Returns all elements in the range specified by the begin and end keys.
 void release()
          Performs resource cleanup tasks such as closing files, or database connections.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexStoreReader

public IndexStoreReader(RandomAccessObjectStoreReader<T> indexStoreReader,
                        java.util.Comparator<K> ordering)
Creates a new instance.

Parameters:
indexStoreReader - Provides access to the index data.
ordering - A comparator that sorts index elements desired index key ordering.
Method Detail

get

public T get(K key)
Returns the index element identified by id.

Parameters:
key - The identifier for the index element to be retrieved.
Returns:
The requested object.

getRange

public java.util.Iterator<T> getRange(K beginKey,
                                      K endKey)
Returns all elements in the range specified by the begin and end keys. All elements with keys matching and lying between the two keys will be returned.

Parameters:
beginKey - The key marking the beginning of the required index elements.
endKey - The key marking the end of the required index elements. The identifier for the index element to be retrieved.
Returns:
An iterator pointing to the requested range.

release

public void release()
Performs resource cleanup tasks such as closing files, or database connections. This must be called after all processing is complete and may be called multiple times. Implementations must call release on any nested Releasable objects. It should be called within a finally block to ensure it is called in exception scenarios.

Specified by:
release in interface Releasable