org.apache.directory.server.core.avltree
Class AvlTreeSingleton<K>

java.lang.Object
  extended by org.apache.directory.server.core.avltree.AvlTreeSingleton<K>
All Implemented Interfaces:
AvlTree<K>

public class AvlTreeSingleton<K>
extends java.lang.Object
implements AvlTree<K>

An immutable AvlTree wrapping a singleton.

Version:
$Rev$, $Date$
Author:
Apache Directory Project

Constructor Summary
AvlTreeSingleton(K key, java.util.Comparator<K> comparator)
           
 
Method Summary
 LinkedAvlNode<K> find(K key)
          Find a LinkedAvlNode with the given key value in the tree.
 LinkedAvlNode<K> findGreater(K key)
          Finds a LinkedAvlNode whose key is higher than the given key.
 LinkedAvlNode<K> findGreaterOrEqual(K key)
          Finds a LinkedAvlNode whose key is higher than the given key.
 LinkedAvlNode<K> findLess(K key)
          Finds a LinkedAvlNode whose key is lower than the given key.
 LinkedAvlNode<K> findLessOrEqual(K key)
          Finds a LinkedAvlNode whose key is lower than the given key.
 java.util.Comparator<K> getComparator()
          
 LinkedAvlNode<K> getFirst()
          
 java.util.List<K> getKeys()
          
 LinkedAvlNode<K> getLast()
          
 LinkedAvlNode<K> getRoot()
          
 int getSize()
          returns the number of nodes present in this tree.
 K insert(K key)
          Inserts a LinkedAvlNode with the given key.
 boolean isEmpty()
          Tests if the tree is logically empty.
 void printTree()
          Prints the contents of AVL tree in pretty format
 K remove(K key)
          Removes the LinkedAvlNode present in the tree with the given key value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AvlTreeSingleton

public AvlTreeSingleton(K key,
                        java.util.Comparator<K> comparator)
Method Detail

find

public LinkedAvlNode<K> find(K key)
Find a LinkedAvlNode with the given key value in the tree.

Specified by:
find in interface AvlTree<K>
Parameters:
key - the key to find
Returns:
the list of traversed LinkedAvlNode.

findGreater

public LinkedAvlNode<K> findGreater(K key)
Finds a LinkedAvlNode whose key is higher than the given key.

Specified by:
findGreater in interface AvlTree<K>
Parameters:
key - the key
Returns:
the LinkedAvlNode whose key is greater than the given key ,
null if there is no node with a higher key than the given key.

findGreaterOrEqual

public LinkedAvlNode<K> findGreaterOrEqual(K key)
Finds a LinkedAvlNode whose key is higher than the given key.

Specified by:
findGreaterOrEqual in interface AvlTree<K>
Parameters:
key - the key
Returns:
the LinkedAvlNode whose key is greater than the given key ,
null if there is no node with a higher key than the given key.

findLess

public LinkedAvlNode<K> findLess(K key)
Finds a LinkedAvlNode whose key is lower than the given key.

Specified by:
findLess in interface AvlTree<K>
Parameters:
key - the key
Returns:
the LinkedAvlNode whose key is lower than the given key ,
null if there is no node with a lower key than the given key.

findLessOrEqual

public LinkedAvlNode<K> findLessOrEqual(K key)
Finds a LinkedAvlNode whose key is lower than the given key.

Specified by:
findLessOrEqual in interface AvlTree<K>
Parameters:
key - the key
Returns:
the LinkedAvlNode whose key is lower than the given key ,
null if there is no node with a lower key than the given key.

getComparator

public java.util.Comparator<K> getComparator()

Specified by:
getComparator in interface AvlTree<K>
Returns:
the comparator associated with this tree

getFirst

public LinkedAvlNode<K> getFirst()

Specified by:
getFirst in interface AvlTree<K>
Returns:
The first element of this tree

getKeys

public java.util.List<K> getKeys()

Specified by:
getKeys in interface AvlTree<K>
Returns:
a list of the stored keys in this tree

getLast

public LinkedAvlNode<K> getLast()

Specified by:
getLast in interface AvlTree<K>
Returns:
The last element in this tree

getRoot

public LinkedAvlNode<K> getRoot()

Specified by:
getRoot in interface AvlTree<K>
Returns:
the root element of this tree (ie, not the first, but the topmost element)

getSize

public int getSize()
returns the number of nodes present in this tree.

Specified by:
getSize in interface AvlTree<K>
Returns:
the number of nodes present in this tree

insert

public K insert(K key)
Description copied from interface: AvlTree
Inserts a LinkedAvlNode with the given key.

Specified by:
insert in interface AvlTree<K>
Parameters:
key - the item to be inserted
Returns:
the replaced key if it already exists Note: Ignores if a node with the given key already exists.

isEmpty

public boolean isEmpty()
Description copied from interface: AvlTree
Tests if the tree is logically empty.

Specified by:
isEmpty in interface AvlTree<K>
Returns:
true if the tree is empty, false otherwise

printTree

public void printTree()
Description copied from interface: AvlTree
Prints the contents of AVL tree in pretty format

Specified by:
printTree in interface AvlTree<K>

remove

public K remove(K key)
Description copied from interface: AvlTree
Removes the LinkedAvlNode present in the tree with the given key value

Specified by:
remove in interface AvlTree<K>
Parameters:
key - the value of the node to be removed
Returns:
the removed key, if any, or null if the key does not exist


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.