Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.icl.saxon.sort
Class BinaryTree

    java.lang.Object
      |
      +--com.icl.saxon.sort.BinaryTree

public class BinaryTree
extends java.lang.Object

A Binary Tree used for sorting. Similar to the java.util.Dictionary interface except (a) that the keys must be Strings rather than general Objects (b) the results are returned as a Vector, not an Enumeration.

The methods getKeys() and getValues() return values in ascending order of key. The keys are compared using a default Collator which sorts in alphabetical order with intelligent handling of case and accents.

Note that duplicate keys are not allowed: a new entry silently overwrites any previous entry with the same key. If you want to use dulicate keys, append a unique value (for example, a random number) to each one.

Constructor Summary
`BinaryTree()`

Method Summary
`java.lang.Object` | `get(java.lang.Object key)` get(String) returns the value corresponding to a given key, if any
`java.util.Vector` | `getKeys()` getKeys() returns the keys in the tree in sorted order.
`java.util.Vector` | `getValues()` getValues() returns the values in the tree in sorted order.
`boolean` | `isEmpty()` isEmpty() Tests if this binary tree contains no keys.
`static void` | `main(java.lang.String[] args)`
`java.lang.Object` | `put(java.lang.Object key, java.lang.Object value)` put(Object, Object) puts a new entry in the tree, overwriting any previous entry with the same key.
`java.lang.Object` | `remove(java.lang.Object key)` remove(Object) removes the key (and its corresponding value) from this Binary Tree.
`void` | `setAscending(boolean ascending)` Set order.
`void` | `setComparer(Comparer c)` Set the Comparer to be used for the keys in this tree.
`void` | `setDuplicatesAllowed(boolean allow)` Define whether duplicate keys are allowed or not.
`int` | `size()` size()

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### BinaryTree

    public BinaryTree()

Method Detail

### setAscending

    public void setAscending(boolean ascending)

  Set order. This must be called before any nodes are added to the tree. Default is ascending order

  Parameters:
    `ascending` - true indicates ascending order; false indicates descending

### setDuplicatesAllowed

    public void setDuplicatesAllowed(boolean allow)

  Define whether duplicate keys are allowed or not. If duplicates are allowed, objects with the same key value will be sequenced in order of arrival. If duplicates are not allowed, a new value will overwrite an existing value with the same key.

### setComparer

    public void setComparer(Comparer c)

  Set the Comparer to be used for the keys in this tree. At the time this is called, the tree must be empty

### getValues

    public java.util.Vector getValues()

  getValues() returns the values in the tree in sorted order.

  Returns:
    an Vector containing the values in this BinaryTree (in key order).

### getKeys

    public java.util.Vector getKeys()

  getKeys() returns the keys in the tree in sorted order.

  Returns:
    an Vector containing the keys in this BinaryTree (in key order).

### get

    public java.lang.Object get(java.lang.Object key)

  get(String) returns the value corresponding to a given key, if any

  Parameters:
    `key` - The key value being sought
  Returns:
    the value to which the key is mapped in this binary tree, or null if there is no entry with this key

### isEmpty

    public boolean isEmpty()

  isEmpty() Tests if this binary tree contains no keys.

  Returns:
    true if there are no entries in the tree

### put

    public java.lang.Object put(java.lang.Object key,
                                java.lang.Object value)

  put(Object, Object) puts a new entry in the tree, overwriting any previous entry with the same key.

  Parameters:
    `key` - The value of the key. Note this must be a String, and must not be null.
    `value` - The value to be associated with this key. Must not be null.
  Returns:
    the value previously associated with this key, if there was one. Otherwise null.

### remove

    public java.lang.Object remove(java.lang.Object key)

  remove(Object) removes the key (and its corresponding value) from this Binary Tree. If duplicates are allowed it removes at most one entry with this key

  Parameters:
    `key` - identifies the entry to be removed
  Returns:
    the value that was associated with this key, if there was one. Otherwise null.

### size

    public int size()

  size()

  Returns:
    the number of entries in this binary tree.

### main

    public static void main(java.lang.String[] args)
                     throws java.lang.Exception

    `java.lang.Exception`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD