Skip to content

Version 2.3.0

Choose a tag to compare

@brianburton brianburton released this 13 Feb 03:02
· 532 commits to master since this release

This release contains a mix of performance tweaks and convenience features.

Performance - Faster Builders

The mutable builder objects for JImmutableList and JImmutableRandomAccessList have been rewritten to use less memory. Previously they accumulated all of the values into an ArrayList and then built up an optimal immutable list when the build() method is called. The new builders reduce memory consumption by constructing the lists as elements are added without any extra buffering. The list() and ralist() methods that build lists from arrays, iterators, and collections benefit transparently from this change as well.

Performance - update() Method for Maps

Maps are often used to accumulate values. The general pattern for this involves frequently calling get() to find the current value (if any) for a key then calling assign() with a modified value. This pattern leads to two round trips through the map. The new update() method replaces these two round trips with a single one. The map traverses the tree to find the current value for the key (if any) then calls a lambda to get a new value and applies the change immediately at the node where it belongs. JImmutableListMap and JImmutableSetMap benefit transparently from this change as well.

Performance - Fast List Append for RandomAccessLists

When passing a JImmutableRandomAccessList to one of the insertAllFirst(), insertAllLast(), etc methods or another JImmutableRandomAccessList the append operation can now be performed in the same time as a single value insert. This change takes advantage of the nature of B-Trees to allow almost the entire structure of the smaller of the two lists to be directly added to the larger list to accomplish the append operation n a single update operation.

Utility - New transform() Methods for Lists

The new method constructs a new list of the same type containing new values produced by calling a lambda to convert each value to a new object type.

Utility - New Convenience Methods for Holders

This release adds several convenience methods to the Holder interface.

  • ifPresent(): Takes a Consumer as its sole parameter. If the Holder is filled it calls the Consumer and passes it the value.
  • map(): Takes a Function as its sole parameter. If the Holder is filled it calls the Function and passes it the value. map() returns a Holder containing the mapped value (if any).
  • orElse(): Alias for getValueOr().
  • orElseGet(): Takes a Supplier as its sole parameter. If the Holder is empty it calls the Supplier and returns its result. Otherwise it returns its own value.
  • orElseThrow(): Takes a Supplier as its sole parameter. If the Holder is empty it calls the Supplier to obtain an Exception to throw. Otherwise it returns its own value.

Useful Links

Project Wiki
Collections Overview
Project Javadoc

Maven Coordinates

<dependency>
    <groupId>org.javimmutable</groupId>
    <artifactId>javimmutable-collections</artifactId>
    <version>2.3.0</version>
</dependency>