org.apache.directory.server.xdbm.impl.avl
Class AvlTable<K,V>

java.lang.Object
  extended by org.apache.directory.server.xdbm.AbstractTable<K,V>
      extended by org.apache.directory.server.xdbm.impl.avl.AvlTable<K,V>
All Implemented Interfaces:
Table<K,V>
Direct Known Subclasses:
AvlMasterTable

public class AvlTable<K,V>
extends AbstractTable<K,V>

A Table implementation backed by in memory AVL tree.

Author:
Apache Directory Project

Field Summary
 
Fields inherited from class org.apache.directory.server.xdbm.AbstractTable
count, keyComparator, name, schemaManager, valueComparator
 
Constructor Summary
AvlTable(String name, Comparator<K> keyComparator, Comparator<V> valueComparator, boolean dupsEnabled)
           
 
Method Summary
 void close()
          Closes the underlying Db of this Table.
 int count(K key)
          Gets the count of the number of records in this Table with a specific key: returns the number of duplicates for a key.
 org.apache.directory.shared.ldap.model.cursor.Cursor<org.apache.directory.shared.ldap.model.cursor.Tuple<K,V>> cursor()
          Creates a Cursor that traverses Tuples in a Table.
 org.apache.directory.shared.ldap.model.cursor.Cursor<org.apache.directory.shared.ldap.model.cursor.Tuple<K,V>> cursor(K key)
          Creates a Cursor that traverses Table Tuples for the same key.
 V get(K key)
          Gets the value of a record by key if the key exists.
 int greaterThanCount(K key)
          Gets the number of records greater than or equal to a key value.
 boolean has(K key)
          Checks to see if this table has one or more tuples with a specific key: this is exactly the same as a get call with a check to see if the returned value is null or not.
 boolean has(K key, V value)
          Checks to see if this table has a key with a specific value.
 boolean hasGreaterOrEqual(K key)
          Checks to see if this table has a record with a key greater than or equal to the key argument.
 boolean hasGreaterOrEqual(K key, V val)
          Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value greater than or equal to the value argument provided.
 boolean hasLessOrEqual(K key)
          Checks to see if this table has a record with a key less than or equal to the key argument.
 boolean hasLessOrEqual(K key, V val)
          Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value less than or equal to the value argument provided.
 boolean isDupsEnabled()
          Checks to see if this Table has allows for duplicate keys (a.k.a.
 int lessThanCount(K key)
          Gets the number of records less than or equal to a key value.
 void put(K key, V value)
          Puts a record into this Table.
 void remove(K key)
          Removes all records with a specified key from this Table.
 void remove(K key, V value)
          Removes a single key value pair with a specified key and value from this Table.
 org.apache.directory.shared.ldap.model.cursor.Cursor<V> valueCursor(K key)
          Creates a Cursor that traverses Table values for the same key.
 
Methods inherited from class org.apache.directory.server.xdbm.AbstractTable
count, getKeyComparator, getName, getValueComparator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvlTable

public AvlTable(String name,
                Comparator<K> keyComparator,
                Comparator<V> valueComparator,
                boolean dupsEnabled)
Method Detail

close

public void close()
           throws Exception
Closes the underlying Db of this Table.

Throws:
Exception - on any failures

count

public int count(K key)
          throws Exception
Gets the count of the number of records in this Table with a specific key: returns the number of duplicates for a key.

Parameters:
key - the Object key to count.
Returns:
the number of duplicate records for a key.
Throws:
Exception - if there is a failure to read the underlying Db

get

public V get(K key)
      throws Exception
Gets the value of a record by key if the key exists. If this Table allows duplicate keys then the first key will be returned. If this Table sorts keys then the key will be the smallest key in the Table as specificed by this Table's comparator or the default bytewise lexical comparator.

Parameters:
key - the key of the record
Returns:
the value of the record with the specified key if key exists or null if no such key exists.
Throws:
Exception - if there is a failure to read the underlying Db

greaterThanCount

public int greaterThanCount(K key)
                     throws Exception
Gets the number of records greater than or equal to a key value. The specific key argument provided need not exist for this call to return a non-zero value.

Parameters:
key - the key to use in comparisons
Returns:
the number of keys greater than or equal to the key
Throws:
Exception - if there is a failure to read the underlying db

has

public boolean has(K key)
            throws Exception
Checks to see if this table has one or more tuples with a specific key: this is exactly the same as a get call with a check to see if the returned value is null or not.

Parameters:
key - the Object of the key to check for
Returns:
true if the key exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db

has

public boolean has(K key,
                   V value)
            throws Exception
Checks to see if this table has a key with a specific value.

Parameters:
key - the key to check for
value - the value to check for
Returns:
true if a record with the key and value exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db

hasGreaterOrEqual

public boolean hasGreaterOrEqual(K key)
                          throws Exception
Checks to see if this table has a record with a key greater than or equal to the key argument. The key argument need not exist for this call to return true. The underlying database must sort keys based on a key comparator because this method depends on key ordering.

Parameters:
key - the key to compare keys to
Returns:
true if a Tuple with a key greater than or equal to the key argument exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db

hasGreaterOrEqual

public boolean hasGreaterOrEqual(K key,
                                 V val)
                          throws Exception
Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value greater than or equal to the value argument provided. The key argument MUST exist for this call to return true and the underlying Db must allow for values of duplicate keys to be sorted. The entire basis to this method depends on the fact that tuples of the same key have values sorted according to a valid value comparator. If the table does not support duplicates then an UnsupportedOperationException is thrown.

Parameters:
key - the key
val - the value to compare values to
Returns:
true if a Tuple with a key equal to the key argument and a value greater than the value argument exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db or if the underlying Db is not of the Btree type that allows sorted duplicate values.

hasLessOrEqual

public boolean hasLessOrEqual(K key)
                       throws Exception
Checks to see if this table has a record with a key less than or equal to the key argument. The key argument need not exist for this call to return true. The underlying database must sort keys based on a key comparator because this method depends on key ordering.

Parameters:
key - the key to compare keys to
Returns:
true if a Tuple with a key less than or equal to the key argument exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db

hasLessOrEqual

public boolean hasLessOrEqual(K key,
                              V val)
                       throws Exception
Checks to see if this table has a Tuple with a key equal to the key argument, yet with a value less than or equal to the value argument provided. The key argument MUST exist for this call to return true and the underlying Db must allow for values of duplicate keys to be sorted. The entire basis to this method depends on the fact that tuples of the same key have values sorted according to a valid value comparator. If the table does not support duplicates then an UnsupportedOperationException is thrown.

Parameters:
key - the key
val - the value to compare values to
Returns:
true if a Tuple with a key equal to the key argument and a value less than the value argument exists, false otherwise
Throws:
Exception - if there is a failure to read the underlying Db or if the underlying Db is not of the Btree type that allows sorted duplicate values.

isDupsEnabled

public boolean isDupsEnabled()
Checks to see if this Table has allows for duplicate keys (a.k.a. multiple values for the same key).

Returns:
true if duplicate keys are enabled, false otherwise

lessThanCount

public int lessThanCount(K key)
                  throws Exception
Gets the number of records less than or equal to a key value. The specific key argument provided need not exist for this call to return a non-zero value.

Parameters:
key - the key to use in comparisons
Returns:
the number of keys less than or equal to the key
Throws:
Exception - if there is a failure to read the underlying db

put

public void put(K key,
                V value)
         throws Exception
Puts a record into this Table. Null is not allowed for keys or values and should result in an IllegalArgumentException.

Parameters:
key - the key of the record
value - the value of the record.
Throws:
Exception - if there is a failure to read or write to the underlying Db
IllegalArgumentException - if a null key or value is used

remove

public void remove(K key)
            throws Exception
Removes all records with a specified key from this Table.

Parameters:
key - the key of the records to remove
Throws:
Exception - if there is a failure to read or write to the underlying Db

remove

public void remove(K key,
                   V value)
            throws Exception
Removes a single key value pair with a specified key and value from this Table.

Parameters:
key - the key of the record to remove
value - the value of the record to remove
Throws:
Exception - if there is a failure to read or write to the underlying Db

cursor

public org.apache.directory.shared.ldap.model.cursor.Cursor<org.apache.directory.shared.ldap.model.cursor.Tuple<K,V>> cursor()
                                                                                                                      throws Exception
Creates a Cursor that traverses Tuples in a Table.

Returns:
a Cursor over Tuples containing the key value pairs
Throws:
Exception - if there are failures accessing underlying stores

cursor

public org.apache.directory.shared.ldap.model.cursor.Cursor<org.apache.directory.shared.ldap.model.cursor.Tuple<K,V>> cursor(K key)
                                                                                                                      throws Exception
Creates a Cursor that traverses Table Tuples for the same key. Only Tuples with the provided key will be returned if the key exists at all. If the key does not exist an empty Cursor is returned. The motivation behind this method is to minimize the need for callers to actively constrain Cursor operations based on the Tuples they return to a specific key. This Cursor is naturally limited to return only the tuples for the same key.

Parameters:
key - the duplicate key to return the Tuples of
Returns:
a Cursor over Tuples containing the same key
Throws:
Exception - if there are failures accessing underlying stores

valueCursor

public org.apache.directory.shared.ldap.model.cursor.Cursor<V> valueCursor(K key)
                                                                    throws Exception
Creates a Cursor that traverses Table values for the same key. Only Tuples with the provided key will have their values returned if the key exists at all. If the key does not exist an empty Cursor is returned. The motivation behind this method is to minimize the need for callers to actively constrain Cursor operations to a specific key while removing overheads in creating new Tuples or population one that is reused to return key value pairs. This Cursor is naturally limited to return only the values for the same key.

Parameters:
key - the duplicate key to return the values of
Returns:
a Cursor over values of a key
Throws:
Exception - if there are failures accessing underlying stores


Copyright © 2003-2012 The Apache Software Foundation. All Rights Reserved.