org.jrdf.graph.local.index
Class AbstractIndex<T>

java.lang.Object
  extended by org.jrdf.graph.local.index.AbstractIndex<T>
All Implemented Interfaces:
Serializable, Index<T>
Direct Known Subclasses:
LongIndexMem

public abstract class AbstractIndex<T>
extends Object
implements Index<T>, Serializable

See Also:
Serialized Form

Field Summary
protected  Map<T,ClosableMap<T,Set<T>>> index
           
 
Constructor Summary
protected AbstractIndex()
           
protected AbstractIndex(Map<T,ClosableMap<T,Set<T>>> newIndex)
           
 
Method Summary
 void add(T... triple)
          Adds a triple to a single index.
 void clear()
          Removes all triples from this index.
 void close()
           
 boolean contains(T node)
          Returns true if the value given exists in the index.
 long getSize()
          Returns the number of triples in the index.
abstract  ClosableIterator<T[]> getSubIndex(T first)
          Returns an array of results from the index.
abstract  ClosableIterator<T[]> iterator()
          Returns an iterator which contains all the elements in the graph as an array of distinct longs.
 boolean keyExists(T node)
           
 void remove(T... node)
          Removes a triple from a single index.
 boolean removeSubIndex(T first)
          Removes the given entry of long to set of longs with the given entry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jrdf.graph.local.index.Index
getSubSubIndex
 

Field Detail

index

protected Map<T,ClosableMap<T,Set<T>>> index
Constructor Detail

AbstractIndex

protected AbstractIndex(Map<T,ClosableMap<T,Set<T>>> newIndex)

AbstractIndex

protected AbstractIndex()
Method Detail

add

public void add(T... triple)
Description copied from interface: Index
Adds a triple to a single index. This method defines the internal structure.

Specified by:
add in interface Index<T>
Parameters:
triple - The nodes to add.

contains

public boolean contains(T node)
Description copied from interface: Index
Returns true if the value given exists in the index.

Specified by:
contains in interface Index<T>
Parameters:
node - the key to search for.
Returns:
true if the key exsts.

iterator

public abstract ClosableIterator<T[]> iterator()
Description copied from interface: Index
Returns an iterator which contains all the elements in the graph as an array of distinct longs.

Specified by:
iterator in interface Index<T>
Returns:
an iterator which contains all the elements in the graph as an array of distinct longs.

getSubIndex

public abstract ClosableIterator<T[]> getSubIndex(T first)
Description copied from interface: Index
Returns an array of results from the index. For example, a given subject id is given and the array of predicates and objects.

Specified by:
getSubIndex in interface Index<T>
Parameters:
first - the entry to find.
Returns:
an array containing the results.

remove

public void remove(T... node)
            throws GraphException
Description copied from interface: Index
Removes a triple from a single index.

Specified by:
remove in interface Index<T>
Parameters:
node - the nodes to remove.
Throws:
GraphException - If there was an error revoking the statement, for example if it didn't exist.

keyExists

public boolean keyExists(T node)

removeSubIndex

public boolean removeSubIndex(T first)
Description copied from interface: Index
Removes the given entry of long to set of longs with the given entry. For example, a given subject id is given and it will remove all the associated predicate and objects for that subject.

Specified by:
removeSubIndex in interface Index<T>
Parameters:
first - the entry set to remove.
Returns:
true if the entry set was non-null.

clear

public void clear()
Description copied from interface: Index
Removes all triples from this index.

Specified by:
clear in interface Index<T>

close

public void close()
Specified by:
close in interface Index<T>

getSize

public long getSize()
Description copied from interface: Index
Returns the number of triples in the index.

Specified by:
getSize in interface Index<T>
Returns:
the number of triples in the index.