: Class TreeSet

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

## weiss.util
Class TreeSet

    java.lang.Object
      |
      +--weiss.util.AbstractCollection
            |
            +--weiss.util.TreeSet

All Implemented Interfaces:
  Collection, java.io.Serializable, Set, SortedSet

public class TreeSet
extends AbstractCollection
implements SortedSet

Balanced search tree implementation of SortedSet. Matches are based on comparator or compareTo.

See Also:
  Serialized Form

Constructor Summary
`TreeSet()` Construct an empty TreeSet.
`TreeSet(Collection other)` Construct a TreeSet from any collection.
`TreeSet(Comparator c)` Construct an empty TreeSet with a specified comparator.
`TreeSet(TreeSet other)` Construct a TreeSet from another TreeSet.

Method Summary
`boolean` | `add(java.lang.Object x)` Adds an item to this collection.
`void` | `clear()` Change the size of this collection to zero.
`Comparator` | `comparator()` Return the comparator used by this TreeSet.
`boolean` | `contains(java.lang.Object x)` Tests if some item is in this collection.
`java.lang.Object` | `first()` Find the smallest item in the set.
`java.lang.Object` | `getMatch(java.lang.Object x)` This method is not part of standard Java 1.2.
`Iterator` | `iterator()` Obtains an Iterator object used to traverse the collection.
`java.lang.Object` | `last()` Find the largest item in the set.
`boolean` | `remove(java.lang.Object x)` Removes an item from this collection.
`int` | `size()` Returns the number of items in this collection.

Methods inherited from class weiss.util.AbstractCollection
`equals, hashCode, isEmpty, toArray`

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

Methods inherited from interface weiss.util.Collection
`isEmpty, toArray`

Constructor Detail

### TreeSet

    public TreeSet()

  Construct an empty TreeSet.

### TreeSet

    public TreeSet(Comparator c)

  Construct an empty TreeSet with a specified comparator.

### TreeSet

    public TreeSet(TreeSet other)

  Construct a TreeSet from another TreeSet.

### TreeSet

    public TreeSet(Collection other)

  Construct a TreeSet from any collection. Uses an O( N log N ) algorithm, but could be improved.

Method Detail

### comparator

    public Comparator comparator()

  Return the comparator used by this TreeSet.
  Specified by:
    `comparator` in interface `SortedSet`
  Returns:
    the comparator or null if the default comparator is used.

### size

    public int size()

  Returns the number of items in this collection.
  Specified by:
    `size` in interface `Collection`
  Returns:
    the number of items in this collection.

### first

    public java.lang.Object first()

  Find the smallest item in the set.
  Specified by:
    `first` in interface `SortedSet`
  Returns:
    the smallest item.
  Throws:
    `NoSuchElementException` - if the set is empty.

### last

    public java.lang.Object last()

  Find the largest item in the set.
  Specified by:
    `last` in interface `SortedSet`
  Returns:
    the largest item.
  Throws:
    `NoSuchElementException` - if the set is empty.

### getMatch

    public java.lang.Object getMatch(java.lang.Object x)

  This method is not part of standard Java 1.2. Like contains, it checks if x is in the set. If it is, it returns the reference to the matching object; otherwise it returns null.
  Specified by:
    `getMatch` in interface `Set`
  Parameters:
    `x` - the object to search for.
  Returns:
    if contains(x) is false, the return value is null; otherwise, the return value is the object that causes contains(x) to return true.

### contains

    public boolean contains(java.lang.Object x)

  Tests if some item is in this collection.
  Specified by:
    `contains` in interface `Collection`
  Overrides:
    `contains` in class `AbstractCollection`
  Parameters:
    `x` - any object.
  Returns:
    true if this collection contains an item equal to x.

### add

    public boolean add(java.lang.Object x)

  Adds an item to this collection.
  Specified by:
    `add` in interface `Collection`
  Parameters:
    `x` - any object.
  Returns:
    true if this item was added to the collection.

### remove

    public boolean remove(java.lang.Object x)

  Removes an item from this collection.
  Specified by:
    `remove` in interface `Collection`
  Overrides:
    `remove` in class `AbstractCollection`
  Parameters:
    `x` - any object.
  Returns:
    true if this item was removed from the collection.

### clear

    public void clear()

  Change the size of this collection to zero.
  Specified by:
    `clear` in interface `Collection`
  Overrides:
    `clear` in class `AbstractCollection`

### iterator

    public Iterator iterator()

  Obtains an Iterator object used to traverse the collection.
  Specified by:
    `iterator` in interface `Collection`

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