Kevin Bourillon and Jared Levy have posted version 0.8 of the Google Collections library, which extends the standard JDK collections classes with:
- BiMap. A Map that guarantees unique values, and supports an inverse view.
- Multiset. A Collection that may contain duplicate values like a List, yet has order-independent equality like a Set. Often used to represent a histogram.
- Multimap. Similar to Map, but may contain duplicate keys. Has subtypes SetMultimap and ListMultimap providing more specific behavior.
There are also more than a dozen collection implementations, mostly of the interfaces above, but not all. ReferenceMap, for example, is a ConcurrentMap implementation which easily handles any combination of strong, soft or weak keys with strong, soft or weak values.
Static utility classes include:
- Comparators. Natural order, compound, null-friendly, ad-hoc . . .
- Iterators and Iterables. Element-based equality, cycle, concat, partition, filter with predicate, transform with function . . .
- Lists, Sets and Maps. A plethora of convenient factory methods and much more.
- PrimitiveArrays: "boxing"/"unboxing" of primitive arrays
And there's more:
- Forwarding collections
- Constrained collections
- Implementation helpers like AbstractIterator
Changes in this release include:
Added classes
- Collections2: Provides static methods for working with Collection instances
- ImmutableBiMap: An immutable BiMap with reliable user-specified iteration order
- ImmutableMultimap: An immutable ListMultimap with reliable user-specified key and value iteration order
- ImmutableMultiset: An immutable hash-based multiset
- Serialization: Provides static method for serializing collection classes
- UnmodifiableIterator: An iterator that does not support remove()
New functionality
- Added Join methods taking a Map parameter
- Added Comparators.toStringOrder()
- Added Constraints.notNull()
- Added HashMultiset.create() methods
- Added ImmutableList.of() methods taking 2-5 parameters and ImmutableList.copyOf(Iterator)
- Added ImmutableSet.copyOf(Iterator)
- ImmutableSortedSet now extends ImmutableSet
- Added ImmutableSortedSet.orderedBy() and reverseOrder()
- Added contains(), containsNull(), removeAll() and retainAll() methods to Iterables and Iterators
- Added Sets.filter()
- Widespread Javadoc improvements
- Explicit serialized forms for most collection classes
- To support more serialization options, Forwarding classes now have an abstract delegate() method, have a no-argument constructor, and don't implement Serializable
- Moved static ForwardingCollection methods to Iterables
Removed code
- Removed Functions.TRIM_STRING and trimString()
- Removed Objects method deepEquals(), deepHashCode(), deepToString(), and nonNull()
- Removed classes ImmutableBiMapBuilder, ImmutableMultimapBuilder, and LinkedListMultimap
- Removed interface SerializableComparator
- Removed constructor ConcurrentMultiset(ConcurrentMap)
- Removed constructors EnumBiMap(EnumBiMap) and EnumHashBiMap(EnumHashBiMap),
- Removed constructors HashMultiset(int) and HashMultiset(Iterable),
- Removed Maps methods immutableBiMap(), newBiMap(), sortedKeySet(), uniqueIndex(Collection, Function), and uniqueIndex(Iterator, Function)
- Removed Multimaps.immutableMultimap() methods
- Removed Multisets methods emptyMultiset() and immutableMultiset()
Java 5 or later is required.