RELEASE NOTES: COLLECTIONS 2.0
NEW COLLECTIONS
These collections are new to Collections 2.0:
- Bag - A Collection that keeps a count of its members of the same
type, using
hashCode
to check for equality. Suppose
you have a Bag that contains {a, a, b, c}
. Calling
getCount on a
would return 2, while calling
uniqueSet would return {a, b, c}
. Note: this is an
interface with several implementations.
- DoubleOrderedMap - Red-Black tree-based implementation of Map.
This class guarantees
that the map will be in both ascending key order and ascending
value order, sorted according to the natural order for the key's
and value's classes.
- FilterListIterator - A proxy
ListIterator
which
takes a Predicate
instance to filter
out objects from an underlying ListIterator
instance. Only objects for which the specified
Predicate
evaluates to true
are
returned by the iterator.
- HashBag - An implementation of Bag that is backed by a
HashMap.
- MultiMap - This is simply a Map with slightly different semantics.
Instead of returning an Object, it returns a Collection.
So for example, you can put( key, new Integer(1) );
and then a Object get( key ); will return you a Collection
instead of an Integer. This is an interface implemented
by MultiHashMap.
- SequencedHashMap - A map of objects whose mapping entries are
sequenced based on the order in
which they were added.
- SortedBag - A type of Bag that maintains order among its unique
representative members
- TreeBag - An implementation of Bag that is backed by a
TreeMap. Order will be maintained among the unique representative
members.
CHANGED COLLECTIONS
These classes have changed since Collections 1.0:
ArrayIterator
Bugs fixed:
- ArrayIterator can now iterate over arrays of primatives
LRUMap
LRUMap has been reimplemented as a subclass of
SynchronizedHashMap. The new implementation of
LRUMap should be faster, and it also offers true LRU
capabilities; now any get(Object) or
put(Object,Object) from this collection
promotes the key to the Most Recently Used position.
LRUMap 2.0 compatibility changes:
- LRUMap can no longer be cast to a HashMap.
- The removeLRU() method now has a different
signature, and is no longer public. Instead, use
remove(getFirstKey()).
- "Externalized" LRUMap 1.0 Objects cannot be
read by LRUMap 2.0.
New features:
- True LRU algorithm.
- New methods from SequencedHashMap superclass.
- processRemovedLRU(Object key, Object value) method
allows subclasses to perform custom actions on
keys and values that are expunged from the Map.
Bugs fixed:
- calling setMaximumSize(int) will remove excess LRUs
when the current size of the Map exceeds the new
maximum size