public class

TreeBag

extends AbstractMapBag
implements Serializable SortedBag
java.lang.Object
   ↳ org.apache.commons.collections.bag.AbstractMapBag
     ↳ org.apache.commons.collections.bag.TreeBag

Class Overview

Implements SortedBag, using a TreeMap to provide the data storage. This is the standard implementation of a sorted bag.

Order will be maintained among the bag members and can be viewed through the iterator.

A Bag stores each object in the collection together with a count of occurrences. Extra methods on the interface allow multiple copies of an object to be added or removed at once. It is important to read the interface javadoc carefully as several methods violate the Collection interface specification.

Summary

Public Constructors
TreeBag()
Constructs an empty TreeBag.
TreeBag(Comparator comparator)
Constructs an empty bag that maintains order on its unique representative members according to the given Comparator.
TreeBag(Collection coll)
Constructs a TreeBag containing all the members of the specified collection.
Public Methods
Comparator comparator()
Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
Object first()
Returns the first (lowest) member.
Object last()
Returns the last (highest) member.
[Expand]
Inherited Methods
From class org.apache.commons.collections.bag.AbstractMapBag
From class java.lang.Object
From interface java.lang.Iterable
From interface java.util.Collection
From interface org.apache.commons.collections.Bag
From interface org.apache.commons.collections.SortedBag

Public Constructors

public TreeBag ()

Constructs an empty TreeBag.

public TreeBag (Comparator comparator)

Constructs an empty bag that maintains order on its unique representative members according to the given Comparator.

Parameters
comparator the comparator to use

public TreeBag (Collection coll)

Constructs a TreeBag containing all the members of the specified collection.

Parameters
coll the collection to copy into the bag

Public Methods

public Comparator comparator ()

Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.

Returns
  • the comparator in use, or null if natural ordering

public Object first ()

Returns the first (lowest) member.

Returns
  • the first element in the sorted bag

public Object last ()

Returns the last (highest) member.

Returns
  • the last element in the sorted bag