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:
GlobalIndex, LongIndexDb4o, LongIndexMem

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

See Also:
Serialized Form

Field Summary
protected  Map<T,Map<T,Set<T>>> index
           
 
Constructor Summary
protected AbstractIndex()
           
protected AbstractIndex(Map<T,Map<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.
 Map<T,Set<T>> getSubIndex(T first)
          Returns the map of long to set of longs for the given entry of the index.
 Iterator<Map.Entry<T,Map<T,Set<T>>>> iterator()
          Returns an iterator which contains all the elements in the graph as a collections of distinct longs, contains a map of longs to other 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
 

Field Detail

index

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

AbstractIndex

protected AbstractIndex(Map<T,Map<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 Iterator<Map.Entry<T,Map<T,Set<T>>>> iterator()
Description copied from interface: Index
Returns an iterator which contains all the elements in the graph as a collections of distinct longs, contains a map of longs to other longs. This prevents any duplication.

Specified by:
iterator in interface Index<T>
Returns:
an iterator which contains all the elements in the graph as a collections of distinct longs, contains a map of longs to other longs. This prevents any duplication.

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)

getSubIndex

public Map<T,Set<T>> getSubIndex(T first)
Description copied from interface: Index
Returns the map of long to set of longs for the given entry of the index. For example, a given subject id is given and it returns a map of predicates to objects.

Specified by:
getSubIndex in interface Index<T>
Parameters:
first - the entry set to find.
Returns:
a map containing the list of longs to set of longs.

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.