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.
| Modifier and Type | Field and Description |
|---|---|
| private static final long | serialVersionUID
Serial version lock |
| Access | Constructor and Description |
|---|---|
| public | |
| public | TreeBag(final Comparator<? super E>
the comparator to use comparator)Constructs an empty bag that maintains order on its unique representative
members according to the given |
| public | TreeBag(final Collection<? extends E>
the collection to copy into the bag coll)Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | add(final E
the object to add object)Overrides org. Implements org. |
| public Comparator | comparator()
Implements org. |
| public E | first()
Implements org. |
| protected SortedMap | getMap()
Overrides org. |
| public E | |
| private void | |
| private void |
| serialVersionUID | back to summary |
|---|---|
| private static final long serialVersionUID Serial version lock | |
| TreeBag | back to summary |
|---|---|
| public TreeBag() Constructs an empty | |
| TreeBag | back to summary |
|---|---|
| public TreeBag(final Comparator<? super E> comparator) Constructs an empty bag that maintains order on its unique representative
members according to the given
| |
| TreeBag | back to summary |
|---|---|
| public TreeBag(final Collection<? extends E> coll) Constructs a
| |
| add | back to summary |
|---|---|
| public boolean add(final E object) Overrides org. Implements org. Doc from org. (Violation) Adds one copy of the specified object to the Bag.
If the object is already in the
Since this method always increases the size of the bag,
according to the
| |
| comparator | back to summary |
|---|---|
| public Comparator Implements org. Doc from org. Returns the comparator associated with this sorted set, or null if it uses its elements' natural ordering.
| |
| first | back to summary |
|---|---|
| public E first() Implements org. Doc from org. Returns the first (lowest) member.
| |
| getMap | back to summary |
|---|---|
| protected SortedMap Overrides org. Doc from org. Utility method for implementations to access the map that backs this bag. Not intended for interactive use outside of subclasses.
| |
| last | back to summary |
|---|---|
| public E last() Implements org. Doc from org. Returns the last (highest) member.
| |
| readObject | back to summary |
|---|---|
| private void readObject(final ObjectInputStream in) throws IOException, ClassNotFoundException Read the bag in using a custom routine.
| |
| writeObject | back to summary |
|---|---|
| private void writeObject(final ObjectOutputStream out) throws IOException Write the bag out using a custom routine.
| |