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
boolean
|
add(Object object, int nCopies)
Adds a new element to the bag, incrementing its count in the map.
|
boolean
|
add(Object object)
Adds a new element to the bag, incrementing its count in the underlying map.
|
boolean
|
addAll(Collection coll)
Invokes add(Object) for each element in the given collection.
|
void
|
clear()
Clears the bag by clearing the underlying map.
|
boolean
|
contains(Object object)
Determines if the bag contains the given element by checking if the
underlying map contains the element as a key.
|
boolean
|
containsAll(Collection coll)
Determines if the bag contains the given elements.
|
void
|
doReadObject(Map map, ObjectInputStream in)
Read the map in using a custom routine.
|
void
|
doWriteObject(ObjectOutputStream out)
Write the map out using a custom routine.
|
boolean
|
equals(Object object)
Compares this Bag to another.
|
int
|
getCount(Object object)
Returns the number of occurrence of the given element in this bag
by looking up its count in the underlying map.
|
Map
|
getMap()
Utility method for implementations to access the map that backs
this bag.
|
int
|
hashCode()
Gets a hash code for the Bag compatible with the definition of equals.
|
boolean
|
isEmpty()
Returns true if the underlying map is empty.
|
Iterator
|
iterator()
Gets an iterator over the bag elements.
|
boolean
|
remove(Object object, int nCopies)
Removes a specified number of copies of an object from the bag.
|
boolean
|
remove(Object object)
Removes all copies of the specified object from the bag.
|
boolean
|
removeAll(Collection coll)
Removes objects from the bag according to their count in the specified collection.
|
boolean
|
retainAll(Collection coll)
Remove any members of the bag that are not in the given
bag, respecting cardinality.
|
int
|
size()
Returns the number of elements in this bag.
|
Object[]
|
toArray()
Returns an array of all of this bag's elements.
|
Object[]
|
toArray(Object[] array)
Returns an array of all of this bag's elements.
|
String
|
toString()
Implement a toString() method suitable for debugging.
|
Set
|
uniqueSet()
Returns an unmodifiable view of the underlying map's key set.
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
java.lang.Iterable
|
From interface
java.util.Collection
abstract
boolean
|
add(E arg0)
|
abstract
boolean
|
addAll(Collection<? extends E> arg0)
|
abstract
void
|
clear()
|
abstract
boolean
|
contains(Object arg0)
|
abstract
boolean
|
containsAll(Collection<?> arg0)
|
abstract
boolean
|
equals(Object arg0)
|
abstract
int
|
hashCode()
|
abstract
boolean
|
isEmpty()
|
abstract
Iterator<E>
|
iterator()
|
abstract
boolean
|
remove(Object arg0)
|
abstract
boolean
|
removeAll(Collection<?> arg0)
|
abstract
boolean
|
retainAll(Collection<?> arg0)
|
abstract
int
|
size()
|
abstract
<T>
T[]
|
toArray(T[] arg0)
|
abstract
Object[]
|
toArray()
|
|
From interface
org.apache.commons.collections.Bag
abstract
boolean
|
add(Object object, int nCopies)
Adds nCopies copies of the specified object to the Bag.
|
abstract
boolean
|
add(Object object)
(Violation)
Adds one copy the specified object to the Bag.
|
abstract
boolean
|
containsAll(Collection coll)
(Violation)
Returns true if the bag contains all elements in
the given collection, respecting cardinality.
|
abstract
int
|
getCount(Object object)
Returns the number of occurrences (cardinality) of the given
object currently in the bag.
|
abstract
Iterator
|
iterator()
Returns an Iterator over the entire set of members,
including copies due to cardinality.
|
abstract
boolean
|
remove(Object object)
(Violation)
Removes all occurrences of the given object from the bag.
|
abstract
boolean
|
remove(Object object, int nCopies)
Removes nCopies copies of the specified object from the Bag.
|
abstract
boolean
|
removeAll(Collection coll)
(Violation)
Remove all elements represented in the given collection,
respecting cardinality.
|
abstract
boolean
|
retainAll(Collection coll)
(Violation)
Remove any members of the bag that are not in the given
collection, respecting cardinality.
|
abstract
int
|
size()
Returns the total number of items in the bag across all types.
|
abstract
Set
|
uniqueSet()
Returns a Set of unique elements in the Bag.
|
|
From interface
org.apache.commons.collections.SortedBag
abstract
Comparator
|
comparator()
Returns the comparator associated with this sorted set, or null
if it uses its elements' natural ordering.
|
abstract
Object
|
first()
Returns the first (lowest) member.
|
abstract
Object
|
last()
Returns the last (highest) member.
|
|
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