Package com.db4o.foundation
Class Tree<T>
- java.lang.Object
-
- com.db4o.foundation.Tree<T>
-
- All Implemented Interfaces:
DeepClone
,ShallowClone
,Visitable<T>
- Direct Known Subclasses:
QPending
,TreeInt
,TreeObject
public abstract class Tree<T> extends java.lang.Object implements ShallowClone, DeepClone, Visitable<T>
-
-
Field Summary
Fields Modifier and Type Field Description Tree<T>
_preceding
int
_size
Tree<T>
_subsequent
-
Constructor Summary
Constructors Constructor Description Tree()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
accept(Visitor4<T> visitor)
<V extends Tree<T>>
Vadd(V newNode)
<V extends Tree<T>>
Vadd(V newNode, int cmp)
On adding a node to a tree, if it already exists, and if Tree#duplicates() returns false, #isDuplicateOf() will be called.static <T,V extends Tree<T>>
Vadd(V oldTree, V newTree)
Tree
addedOrExisting()
On adding a node to a tree, if it already exists, and if Tree#duplicates() returns false, #onAttemptToAddDuplicate() will be called and the existing node will be stored in this._preceding.Tree
balance()
Tree
balanceCheckNulls()
void
calculateSize()
abstract int
compare(Tree a_to)
returns 0, if keys are equal uses this - other returns positive if this is greater than a_to returns negative if this is smaller than a_tostatic Tree
deepClone(Tree a_tree, java.lang.Object a_param)
java.lang.Object
deepClone(java.lang.Object a_param)
The parameter allows passing one new object so parent references can be corrected on children.static int
depth(Tree tree)
boolean
duplicates()
Tree
filter(Predicate4 a_filter)
Tree<T>
find(Tree<T> template)
static <T> Tree<T>
find(Tree<T> inTree, Tree<T> template)
static Tree
findGreaterOrEqual(Tree a_in, Tree a_finder)
static Tree
findSmaller(Tree a_in, Tree a_node)
Tree<T>
first()
abstract T
key()
Tree
last()
static Tree
last(Tree tree)
int
nodes()
Tree
onAttemptToAddDuplicate(Tree oldNode)
int
ownSize()
Tree
remove()
void
removeChildren()
Tree
removeFirst()
static Tree
removeLike(Tree from, Tree a_find)
<V extends Tree<T>>
VremoveLike(V a_find)
Tree
removeNode(Tree a_tree)
java.lang.Object
root()
Tree
rotateLeft()
Tree
rotateRight()
void
setSizeOwn()
void
setSizeOwnPlus(Tree tree)
void
setSizeOwnPlus(Tree tree1, Tree tree2)
void
setSizeOwnPreceding()
void
setSizeOwnPrecedingSubsequent()
void
setSizeOwnSubsequent()
java.lang.Object
shallowClone()
protected Tree
shallowCloneInternal(Tree tree)
int
size()
static int
size(Tree a_tree)
static void
traverse(Tree tree, Tree startingNode, CancellableVisitor4 visitor)
Traverses a tree with a starting point node.static void
traverse(Tree tree, Visitor4 visitor)
<V extends Tree<T>>
voidtraverse(Visitor4<V> visitor)
void
traverseFromLeaves(Visitor4 a_visitor)
boolean
wasAddedToTree()
-
-
-
Method Detail
-
add
public static final <T,V extends Tree<T>> V add(V oldTree, V newTree)
-
add
public <V extends Tree<T>> V add(V newNode, int cmp)
On adding a node to a tree, if it already exists, and if Tree#duplicates() returns false, #isDuplicateOf() will be called. The added node can then be asked for the node that prevails in the tree using #duplicateOrThis(). This mechanism allows doing find() and add() in one run.
-
addedOrExisting
public Tree addedOrExisting()
On adding a node to a tree, if it already exists, and if Tree#duplicates() returns false, #onAttemptToAddDuplicate() will be called and the existing node will be stored in this._preceding. This node node can then be asked for the node that prevails in the tree on adding, using the #addedOrExisting() method. This mechanism allows doing find() and add() in one run.
-
wasAddedToTree
public boolean wasAddedToTree()
-
balance
public final Tree balance()
-
balanceCheckNulls
public Tree balanceCheckNulls()
-
calculateSize
public void calculateSize()
-
compare
public abstract int compare(Tree a_to)
returns 0, if keys are equal uses this - other returns positive if this is greater than a_to returns negative if this is smaller than a_to
-
deepClone
public java.lang.Object deepClone(java.lang.Object a_param)
Description copied from interface:DeepClone
The parameter allows passing one new object so parent references can be corrected on children.
-
duplicates
public boolean duplicates()
-
filter
public final Tree filter(Predicate4 a_filter)
-
last
public final Tree last()
-
nodes
public int nodes()
- Returns:
- the number of nodes in this tree for balancing
-
ownSize
public int ownSize()
-
remove
public Tree remove()
-
removeChildren
public void removeChildren()
-
removeFirst
public Tree removeFirst()
-
rotateLeft
public final Tree rotateLeft()
-
rotateRight
public final Tree rotateRight()
-
setSizeOwn
public final void setSizeOwn()
-
setSizeOwnPrecedingSubsequent
public final void setSizeOwnPrecedingSubsequent()
-
setSizeOwnPreceding
public final void setSizeOwnPreceding()
-
setSizeOwnSubsequent
public final void setSizeOwnSubsequent()
-
setSizeOwnPlus
public final void setSizeOwnPlus(Tree tree)
-
size
public static int size(Tree a_tree)
-
size
public int size()
- Returns:
- the number of objects represented.
-
traverse
public static void traverse(Tree tree, Tree startingNode, CancellableVisitor4 visitor)
Traverses a tree with a starting point node. If there is no exact match for the starting node, the next higher will be taken.
-
traverseFromLeaves
public final void traverseFromLeaves(Visitor4 a_visitor)
-
shallowClone
public java.lang.Object shallowClone()
- Specified by:
shallowClone
in interfaceShallowClone
-
key
public abstract T key()
-
root
public java.lang.Object root()
-
depth
public static int depth(Tree tree)
-
-