org.hypergraphdb.indexing
Class HGIndexer

java.lang.Object
  extended by org.hypergraphdb.indexing.HGIndexer
Direct Known Subclasses:
ByPartIndexer, ByTargetIndexer, CompositeIndexer, HGValueIndexer, LinkIndexer

public abstract class HGIndexer
extends java.lang.Object

An HGIndexer represents an atom used internally by HyperGraphDB to manage indices. All indexers apply to a specific atom types. All indexers are responsible for producing a key for the given atom instance being indexed. In addition, when the keys produced are NOT of type byte[], an indexer must provide a ByteArrayConverter capable of translating a key to/from a byte[].

Because indexers are stored as HyperGraphDB atoms, they must obey the Java Beans conventions of having a default constructor and getter/setter pair for each property that must be recorded into storage.

Implementations may also provide a Comparator for keys for sorted indices and when the default byte[] comparator is not suitable.

IMPORTANT:Instances of HGIndexer are frequently used to perform lookup on existing indices. For example, when trying to determine whether an atom of a complex type is being indexed by some projection, one constructs a ByPartIndexer and performs a lookup in the index manager. Thus, it is essential that implementation of HGIndexer provide proper hashCode and equals methods.

Author:
Borislav Iordanov

Constructor Summary
HGIndexer()
           
HGIndexer(HGHandle type)
           
 
Method Summary
abstract  boolean equals(java.lang.Object other)
          Declared to enforce implementation.
abstract  java.util.Comparator<?> getComparator(HyperGraph graph)
           Return a comparator used to compare key values return by this indexer.
abstract  ByteArrayConverter<?> getConverter(HyperGraph graph)
          Return a ByteArrayConverter capable of translating keys returned by this indexer to/from a byte[].
abstract  java.lang.Object getKey(HyperGraph graph, java.lang.Object atom)
           Returns an index key for the given atom.
 HGHandle getType()
           
abstract  int hashCode()
          Declared to enforce implementation.
 void setType(HGHandle type)
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HGIndexer

public HGIndexer()

HGIndexer

public HGIndexer(HGHandle type)
Method Detail

getType

public HGHandle getType()

setType

public void setType(HGHandle type)

getKey

public abstract java.lang.Object getKey(HyperGraph graph,
                                        java.lang.Object atom)

Returns an index key for the given atom.

Parameters:
graph - The current HyperGraph instance.
atom - The atom being indexed.
Returns:
The index key. If the return value is not a byte[], a non-null ByteArrayConverter must be provided by the getConverter method.

getConverter

public abstract ByteArrayConverter<?> getConverter(HyperGraph graph)

Return a ByteArrayConverter capable of translating keys returned by this indexer to/from a byte[].

Parameters:
graph - The current HyperGraph instance.
Returns:
The ByteArrayConverter for type of index keys return by this indexer or null if keys are of type byte[].

getComparator

public abstract java.util.Comparator<?> getComparator(HyperGraph graph)

Return a comparator used to compare key values return by this indexer. Note that the comparator's compare method will be invoked with byte[] parameters. It is the comparator's responsibility to convert them to the appropriate run-time type for performing the comparison if need be.

The method may return null if a default byte-by-byte comparator is to be used.

Parameters:
graph - The current HyperGraph instance.
Returns:
A comparator used to compare key values return by this indexer or null to use a default byte-by-byte comparison of keys.

hashCode

public abstract int hashCode()

Declared to enforce implementation.

Overrides:
hashCode in class java.lang.Object

equals

public abstract boolean equals(java.lang.Object other)

Declared to enforce implementation.

Overrides:
equals in class java.lang.Object