Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


com.tangosol.util
Class Tree

java.lang.Object
  extended by com.tangosol.util.Base
      extended by com.tangosol.util.Tree

All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class Tree
extends Base
implements java.lang.Cloneable, java.io.Serializable

A thread-safe balanced binary search tree.

As of Coherence 3.3 this class is a wrapper around TreeMap.

Note: Where practical, use java.util.TreeMap; including external syncronization as necessary.

Author:
cp 1997.09.05; mf 2007.10.16

Field Summary
protected  java.util.TreeMap m_tree
          The delgate tree.

 

Constructor Summary
Tree()
          Default constructor.

 

Method Summary
 void add(java.lang.Comparable key)
          Add the passed key to the tree.
 boolean addAll(Tree that)
          Adds all of the nodes in the specified Tree to this Tree if they are not already present.
 void clear()
          Remove all nodes from the tree.
 java.lang.Object clone()
          Make a shallow copy of the tree and its nodes.
 boolean contains(java.lang.Comparable key)
          Determine if the passed key is in the tree.
 java.util.Enumeration elements()
          Create an enumerator for the tree's values.
 boolean equals(java.lang.Object obj)
          Test for tree equality.
 java.lang.Object get(java.lang.Comparable key)
          Find the specified key and return its value.
 int getSize()
          Determine the size of the tree.
protected  java.util.Enumeration getUnsynchronizedKeyEnumerator()
          Get an enumerator of the nodes in the tree.
protected  java.util.Enumeration getUnsynchronizedKeyEnumerator(java.lang.Comparable key)
          Get an enumerator of the nodes in the tree.
 boolean isEmpty()
          Test for empty tree.
 java.util.Enumeration keys()
          Create an in-order enumerator for the tree's keys.
 void print()
          In-order printing of the contents of the tree.
 void put(java.lang.Comparable key, java.lang.Object value)
          Add the passed key to the tree and associate the passed value with the key.
 void putAll(Tree that)
          Puts all of the nodes in the specified Tree to this Tree (including the ones that are already present).
 java.lang.Object remove(java.lang.Comparable key)
          Remove the specified key from the tree, returning its associated value.
 boolean removeAll(Tree that)
          Removes from this Tree all of its nodes that are contained in the specified Tree.
 boolean retainAll(Tree that)
          Retains only the nodes in this Tree that are contained in the specified Tree.
 java.lang.String toString()
          Provide a string representation of the tree.

 

Field Detail

m_tree

protected java.util.TreeMap m_tree
The delgate tree.

Constructor Detail

Tree

public Tree()
Default constructor.

Method Detail

add

public void add(java.lang.Comparable key)
Add the passed key to the tree.
Parameters:
key - the key to add to the tree

put

public void put(java.lang.Comparable key,
                java.lang.Object value)
Add the passed key to the tree and associate the passed value with the key. If the key is already in the tree, the passed value will replace the current value stored with the key.
Parameters:
key - the key to add to the tree
value - the object to associate with the key

get

public java.lang.Object get(java.lang.Comparable key)
Find the specified key and return its value.
Parameters:
key - the key to look for in the tree
Returns:
the associated value or null if the key is not in the tree

contains

public boolean contains(java.lang.Comparable key)
Determine if the passed key is in the tree.
Parameters:
key - the key to look for in the tree
Returns:
true if the key is in the tree, false otherwise

remove

public java.lang.Object remove(java.lang.Comparable key)
Remove the specified key from the tree, returning its associated value.
Parameters:
key - the key to look for in the tree
Returns:
the associated value (which can be null) or null if the key is not in the tree

clear

public void clear()
Remove all nodes from the tree.

getSize

public int getSize()
Determine the size of the tree.
Returns:
the number of nodes in the tree

isEmpty

public boolean isEmpty()
Test for empty tree.
Returns:
true if tree has no nodes

keys

public java.util.Enumeration keys()
Create an in-order enumerator for the tree's keys.
Returns:
an enumerator of the tree's keys

elements

public java.util.Enumeration elements()
Create an enumerator for the tree's values.
Returns:
an enumerator of the tree's values (in the same order that the keys were returned)

addAll

public boolean addAll(Tree that)
Adds all of the nodes in the specified Tree to this Tree if they are not already present. This operation effectively modifies this Tree so that its value is the union of the two Trees. The behavior of this operation is unspecified if the specified Tree is modified while the operation is in progress.
Returns:
true if this Tree changed as a result of the call.
See Also:
Collection.addAll(Collection)

putAll

public void putAll(Tree that)
Puts all of the nodes in the specified Tree to this Tree (including the ones that are already present). This operation effectively modifies this Tree so that its value is the union of the two Trees. The behavior of this operation is unspecified if the specified Tree is modified while the operation is in progress.

retainAll

public boolean retainAll(Tree that)
Retains only the nodes in this Tree that are contained in the specified Tree. In other words, removes from this Tree all of its nodes that are not contained in the specified Tree. This operation effectively modifies this Tree so that its value is the intersection of the two Trees.
Returns:
true if this Collection changed as a result of the call.
See Also:
Collection.retainAll(Collection)

removeAll

public boolean removeAll(Tree that)
Removes from this Tree all of its nodes that are contained in the specified Tree. This operation effectively modifies this Tree so that its value is the asymmetric set difference of the two Trees.
Returns:
true if this Tree changed as a result of the call.
See Also:
Collection.removeAll(Collection)

toString

public java.lang.String toString()
Provide a string representation of the tree.

equals

public boolean equals(java.lang.Object obj)
Test for tree equality.

clone

public java.lang.Object clone()
Make a shallow copy of the tree and its nodes. Note that cloning does make new copies of each node.

print

public void print()
In-order printing of the contents of the tree.

getUnsynchronizedKeyEnumerator

protected java.util.Enumeration getUnsynchronizedKeyEnumerator()
Get an enumerator of the nodes in the tree. This enumerator is not in any way thread-safe, so the tree should be synchronized for as long as this enumerator is in use. Note: Purposefully package private; used by StringTable

getUnsynchronizedKeyEnumerator

protected java.util.Enumeration getUnsynchronizedKeyEnumerator(java.lang.Comparable key)
Get an enumerator of the nodes in the tree. This enumerator is not in any way thread-safe, so the tree should be synchronized for as long as this enumerator is in use. Note: Purposefully package private; used by StringTable

Skip navigation links

Oracle® Coherence Java API Reference
Release 12.1.2.0.3

E26043-02


Copyright © 2000, 2014, Oracle and/or its affiliates. All rights reserved.