7.0.0 (October 2015)
Acquiring GS Collections
Maven
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections-api</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections-testutils</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.goldmansachs</groupId>
<artifactId>gs-collections-forkjoin</artifactId>
<version>7.0.0</version>
</dependency>
Ivy
<dependency org="com.goldmansachs" name="gs-collections-api" rev="7.0.0" />
<dependency org="com.goldmansachs" name="gs-collections" rev="7.0.0" />
<dependency org="com.goldmansachs" name="gs-collections-testutils" rev="7.0.0" />
<dependency org="com.goldmansachs" name="gs-collections-forkjoin" rev="7.0.0"/>
Breaking Changes
MutableCollection.removeIf()
now returnsboolean
.- Sorted sets, bags, and maps implement
ReversibleIterable
. AddedOrderedMap
interface to represent a linked hash map. - Overrode
BiMap.partition()
to returnPartitionUnsortedSet
. UnifiedMap
andUnifiedSet
now throw if constructed with a load factor greater than 1.toStringOfItemToCount()
inImmutableEmptyBag
now consistent with other Bags.
Returns"{}"
instead of""
New Functionality
Primitive Collections
<Primitive>List.binarySearch()
Fixes #20
ObjectPrimitiveHashMapWithHashingStrategy
Similar to ObjectPrimitiveHashMap
but uses a HashingStrategy
to hash and compare keys. Analogous to UnifiedMapWithHashingStrategy
.
<Primitive>Iterable.each()
Behaves exactly same as <Primitive>Iterable.forEach()
. Added to be in sync with RichIterable.each(Procedure)
that was introduced in 6.0 to avoid ambiguity conflict with Iterable.forEach(Consumer)
.
Lazy<Primitive>Iterable.collect<Primitive>()
aggregateInPlaceBy()
, aggregateBy()
, zip()
, zipWithIndex()
, partition()
, selectInstancesOf()
, collectIf()
, groupBy()
, and groupByEach()
on MutablePrimitiveObjectMap
Use the Kahan summation algorithm on sum()
and sumBy()
methods on primitive collections
Other new Functionality
CharAdapter
, CodePointAdapter
and CodePointList
CharAdapter
implementsCharSequence
andImmutableCharList
, and it represents String as a collection of char values.CharPointAdapter
implementsCharSequence
andImmutableIntList
. It behaves similarly toCharAdapter
but it represents String as the unicode codepoint values that are ints.CharPointList
is similar toCharPointAdapter
but it calculates and caches the unicode code point values as an ImmutableIntList internally.
CharAdapter chars = CharAdapter.adapt("This is an example");
CodePointAdapter codePoints = CodePointAdapter.adapt("Can you read this Kanji \"\uD840\uDC00\"? I cannot.");
CodePointList codePointList = CodePointList.from("BMP stands for Basic Multilingual Pane. \"\uD840\uDC00\" is a unicode character outside BMP.");
System.out.println("Upper case: " + chars.collectChar(Character::toUpperCase));
System.out.println("Unicode character outside Basic Multilingual Pane: " + codePoints.reject(Character::isBmpCodePoint).distinct());
System.out.println("English only: " + codePointList.reject(Character::isIdeographic));
Prints
Upper case: THIS IS AN EXAMPLE
Unicode character outside Basic Multilingual Pane: 𠀀
English only: BMP stands for Basic Multilingual Pane. "" is a unicode character outside BMP.
ImmutableSortedBag
ListIterable.distinct(HashingStrategy)
Returns a new ListIterable
containing the distinct elements in this list. Conceptually similar to new UnifiedSetWithHashingStrategy(hashingStrategy, listIterable).toList()
but retains the original order.
MutableBagMultimap.putOccurrences(K key, V value, int occurrences)
Adds occurrences
of value
to the MutableBag
at key
in the multimap.
MutableList.shuffleThis(): MutableList
Shuffles this list and returns this list. Overload optionally takes a Random
.
Predicates.cast()
and Functions.cast()
Allows a Java 8 lambda or method reference to be used in a method taking a predicate or a function without requiring a cast. The methods can be used in places where two or more method overloads could apply when used with a lambda or method reference.
Lists.mutable.of(1, 2, null).removeIf(each -> each == null);
This code fails to compile with the following error.
Error: java: reference to removeIf is ambiguous
both method removeIf(java.util.function.Predicate<? super E>) in java.util.Collection and method removeIf(com.gs.collections.api.block.predicate.Predicate<? super T>) in com.gs.collections.api.collection.MutableCollection match
You can work around the problem by using a cast or the method Predicates.cast()
.
Lists.mutable.of(1, 2, null).removeIf(Predicates.cast(each -> each == null));
Add factory method for creating mutable sets and maps of a given initial capacity.
For example: Sets.mutable.withInitialCapacity(100)
Optimizations and Performance Tests
- Optimize
FastList.addAll()
andUnifiedSet.addAll()
forRandomAccess
lists. - Optimize
UnifiedMap
's short-circuit methods to not delegate to an iterator. - Refactor
ImmutableSortedBag.newWith()
andnewWithout()
to take O(n) time. - Add JDK 8 Streams based JMH tests for
FastList
. - Add JMH Tests for
HashMap<Integer, Integer>
Bug Fixes
- Fix bug in
CollectIterable.toArray()
where it returnsT[]
instead ofObject[]
. - Fix iterator's
remove()
method inObjectPrimitiveHashMap
so that it doesn't rehash. - Fix code point iteration in
StringIterate
and provideCharAdapter
andCodePointList
as OO alternatives for string iteration.
Documentation and Deprecation
- Add information about required Java versions to
README.md
. Fixes #18. - Enhance Javadoc of
Iterate
. - Update Javadoc in
InternalIterable
andRichIterable
to include Java 8 lambda examples. - Deprecate
ArrayIterate.sort()
and recommend direct calls toArrays.sort()
. - Deprecate overloaded methods in
StringIterate
and add specialization alternatives that work better with Java 8 lambdas.