org.javimmutable.collections.tree
Class TreeNode<K,V>

java.lang.Object
  extended by org.javimmutable.collections.tree.TreeNode<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
Cursorable<JImmutableMap.Entry<K,V>>
Direct Known Subclasses:
EmptyNode, LeafNode, ThreeNode, TwoNode

@Immutable
public abstract class TreeNode<K,V>
extends Object
implements Cursorable<JImmutableMap.Entry<K,V>>

Abstract base class for 2-3 tree nodes. Provides public methods for searching and modifying the tree and package private methods used to implement the public methods.


Constructor Summary
TreeNode()
           
 
Method Summary
abstract  void addEntriesTo(Collection<JImmutableMap.Entry<K,V>> collection)
          Adds this node's value and all of its children's value to the collection.
 TreeNode<K,V> assign(Comparator<K> comparator, K key, V value, MutableDelta sizeDelta)
          Assign the specified value to the specified key.
abstract  Cursor<JImmutableMap.Entry<K,V>> cursor()
          Returns a Cursor visiting all entries in sorted order.
 TreeNode<K,V> delete(Comparator<K> comparator, K key, MutableDelta sizeDelta)
          Deletes the specified key.
abstract  Holder<V> find(Comparator<K> comparator, K key)
          Return a (possibly empty) Holder containing the value matching key.
abstract  Holder<JImmutableMap.Entry<K,V>> findEntry(Comparator<K> comparator, K key)
          Return a (possibly empty) Holder containing the an Entry matching key.
abstract  V getValueOr(Comparator<K> comparator, K key, V defaultValue)
          Return the value matching key or defaultValue if no match is found.
 boolean isEmpty()
          Return true if this node contains no children or value.
static
<K,V> TreeNode<K,V>
of()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TreeNode

public TreeNode()
Method Detail

of

public static <K,V> TreeNode<K,V> of()

getValueOr

public abstract V getValueOr(Comparator<K> comparator,
                             K key,
                             V defaultValue)
Return the value matching key or defaultValue if no match is found. Searches this node and its appropriate children.

Parameters:
comparator -
key -
defaultValue -
Returns:

find

public abstract Holder<V> find(Comparator<K> comparator,
                               K key)
Return a (possibly empty) Holder containing the value matching key. Searches this node and its appropriate children.

Parameters:
comparator -
key -
Returns:

findEntry

public abstract Holder<JImmutableMap.Entry<K,V>> findEntry(Comparator<K> comparator,
                                                           K key)
Return a (possibly empty) Holder containing the an Entry matching key. Searches this node and its appropriate children.

Parameters:
comparator -
key -
Returns:

addEntriesTo

public abstract void addEntriesTo(Collection<JImmutableMap.Entry<K,V>> collection)
Adds this node's value and all of its children's value to the collection.

Parameters:
collection -

cursor

@Nonnull
public abstract Cursor<JImmutableMap.Entry<K,V>> cursor()
Returns a Cursor visiting all entries in sorted order.

Specified by:
cursor in interface Cursorable<JImmutableMap.Entry<K,V>>
Returns:

assign

public TreeNode<K,V> assign(Comparator<K> comparator,
                            K key,
                            V value,
                            MutableDelta sizeDelta)
Assign the specified value to the specified key. Returns a node (possibly this same node) reflecting the assignment and updates sizeDelta with the change in size (if any).

Parameters:
comparator -
key -
value -
sizeDelta -
Returns:

delete

public TreeNode<K,V> delete(Comparator<K> comparator,
                            K key,
                            MutableDelta sizeDelta)
Deletes the specified key. Returns a node (possibly this same node) reflecting the deletion and updates sizeDelta with the change in size (if any).

Parameters:
comparator -
key -
sizeDelta -
Returns:

isEmpty

public boolean isEmpty()
Return true if this node contains no children or value.

Returns:


Copyright © 2014 Burton Computer Corporation. All rights reserved.