Eclipse Collections 11.0 Released

Eclipse Collections Logo

Eclipse Collections 11.0 is here!

Eclipse Collections 11.0 in Maven Central
Release announcement on Twitter from Sirisha Pratha

10 years as OSS, 6 years at Eclipse Foundation

Thank you to the release team

Thank you to the community

New Features with Contributor Blogs

  • Added anySatisfyWithOccurrences, allSatisfyWithOccurrences, noneSatisfyWithOccurrences, detectWithOccurrences to Bag.
  • Added putAllMapIterable method to MutableMap.
  • Added withMapIterable to MutableMap.
  • Added newWithMap and newWithMapIterable to ImmutableMap.
  • Added toImmutableList/Set/Bag/Map/BiMap to RichIterable.
  • Added toImmutableSortedList/Set/Bag to RichIterable.
  • Added toImmutableSortedBag/List/Set with Comparator to RichIterable.
  • Added toImmutableSortedBagBy/ListBy/SetBy with Function to RichIterable.
  • Added ClassComparer utility.

More new Features w/ Examples

  • Added selectWithIndex and rejectWithIndex to OrderedIterable and ListIterable.
@Test
public void selectWithIndex()
{
var list = Lists.mutable.with(1, 2, 3, 4);
var actual = list.selectWithIndex((each, i) -> each + i > 3);
var expected = Lists.mutable.with(3, 4);
Assertions.assertEquals(expected, actual);
}

@Test
public void rejectWithIndex()
{
var list = Lists.mutable.with(1, 2, 3, 4);
var actual = list.rejectWithIndex((each, i) -> each + i > 3);
var expected = Lists.mutable.with(1, 2);
Assertions.assertEquals(expected, actual);
}
  • Added covariant overrides for sortThis().
  • Added covariant return types to methods in MultiReaderList that return this.
  • Added primitive singleton iterator.
  • Added toSortedList(Comparator) and toSortedListBy(Function) to primitive iterables.
@Test
public void toSortedListWithComparator()
{
var set = IntSets.immutable.with(1, 2, 3, 4, 5);
var list = set.toSortedList((i1, i2) -> i2 - i1);
var expected = IntLists.immutable.with(5, 4, 3, 2, 1);
Assertions.assertEquals(expected, list);
}

@Test
public void toSortedListByWithFunction()
{
var set = IntSets.immutable.with(1, 2, 3, 4, 5);
var list = set.toSortedListBy(Math::negateExact);
var expected = IntLists.immutable.with(5, 4, 3, 2, 1);
Assertions.assertEquals(expected, list);
}
  • Added isEqual and isSame to Pair and Triple as default methods.
@Test
public void isEqual()
{
Twin<String> pair1 = Tuples.twin("1", "1");
Assertions.assertTrue(pair1.isEqual());
Twin<String> pair2 = Tuples.twin("1", "2");
Assertions.assertFalse(pair2.isEqual());

Triplet<String> triple1 = Tuples.triplet("1", "1", "1");
Assertions.assertTrue(triple1.isEqual());
Triplet<String> triple2 = Tuples.triplet("1", "2", "1");
Assertions.assertFalse(triple2.isEqual());
}

@Test
public void isSame()
{
Twin<String> pair1 = Tuples.identicalTwin("1");
Assertions.assertTrue(pair1.isSame());
Twin<String> pair2 = Tuples.twin("1", new String("1"));
Assertions.assertFalse(pair2.isSame());

Triplet<String> triple1 = Tuples.identicalTriplet("1");
Assertions.assertTrue(triple1.isSame());
Triplet<String> triple2 = Tuples.triplet("1", new String("1"), "1");
Assertions.assertFalse(triple2.isSame());
}
  • Added converters from Pair and Triple to List types.
@Test
public void pairToList()
{
Twin<String> twin = Tuples.twin("1", "2");
var mutableList = Tuples.pairToList(twin);
var fixedSizeList = Tuples.pairToFixedSizeList(twin);
var immutableList = Tuples.pairToImmutableList(twin);
var expected = Lists.mutable.with("1", "2");
Assertions.assertEquals(expected, mutableList);
Assertions.assertEquals(expected, fixedSizeList);
Assertions.assertEquals(expected, immutableList);
}

@Test
public void tripleToList()
{
Triplet<String> triplet = Tuples.identicalTriplet("1");
var mutableList = Tuples.tripleToList(triplet);
var fixedSizeList = Tuples.tripleToFixedSizeList(triplet);
var immutableList = Tuples.tripleToImmutableList(triplet);
var expected = Lists.mutable.with("1", "1", "1");
Assertions.assertEquals(expected, mutableList);
Assertions.assertEquals(expected, fixedSizeList);
Assertions.assertEquals(expected, immutableList);
}
  • Added toImmutableSortedBagBy to Collectors2.
@Test
public void collectors2toImmutableSortedBagBy()
{
List<Integer> list = List.of(1, 2, 2, 3, 3, 3);
ImmutableSortedBag<Integer> bag =
list.stream().collect(
Collectors2.toImmutableSortedBagBy(Math::negateExact));
Comparator<Integer> c =
Functions.toIntComparator(Math::negateExact);
var expected = SortedBags.mutable.with(c, 1, 2, 2, 3, 3, 3);
Assertions.assertEquals(expected, bag);
}
  • Added toImmutableSortedMap and toImmutableSortedMapBy to Collectors2.
@Test
public void collects2toImmutableSortedMap()
{
List<Integer> list = List.of(1, 2, 3);
Comparator<Integer> c =
Functions.toIntComparator(Math::negateExact);
ImmutableSortedMap<Integer, String> map =
list.stream().collect(
Collectors2.toImmutableSortedMap(c, e -> e, String::valueOf));
var expected = SortedMaps.mutable.with(c, 1, "1", 2, "2", 3, "3");
Assertions.assertEquals(expected, map);
}

@Test
public void collects2toImmutableSortedMapBy()
{
List<Integer> list = List.of(1, 2, 3);
Function<Integer, Integer> negate = Math::negateExact;
ImmutableSortedMap<Integer, String> map =
list.stream().collect(
Collectors2.toImmutableSortedMapBy(negate, e -> e, String::valueOf));
Comparator<Integer> c = Comparator.comparing(negate);
var expected = SortedMaps.mutable.with(c, 1, "1", 2, "2", 3, "3");
Assertions.assertEquals(expected, map);
}
  • Added toSortedMap and toSortedMapBy to Collectors2.
@Test
public void collects2toSortedMap()
{
List<Integer> list = List.of(1, 2, 3);
Comparator<Integer> c =
Functions.toIntComparator(Math::negateExact);
MutableSortedMap<Integer, String> map =
list.stream().collect(
Collectors2.toSortedMap(c, e -> e, String::valueOf));
var expected = SortedMaps.mutable.with(c, 1, "1", 2, "2", 3, "3");
Assertions.assertEquals(expected, map);
}

@Test
public void collects2toSortedMapBy()
{
List<Integer> list = List.of(1, 2, 3);
Function<Integer, Integer> negate = Math::negateExact;
MutableSortedMap<Integer, String> map =
list.stream().collect(
Collectors2.toSortedMapBy(negate, e -> e, String::valueOf));
Comparator<Integer> c = Comparator.comparing(negate);
var expected = SortedMaps.mutable.with(c, 1, "1", 2, "2", 3, "3");
Assertions.assertEquals(expected, map);
}

Norwegian Website Translation

Norwegian Translation of the Eclipse Collections website

Three new Eclipse Collections Katas in 2021

And there’s more!

Thank you

Downloads of eclipse-collections for the past 12 months

--

--

--

Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Serve MkDocs on PythonAnywhere

Master Python for Data Science in 30 Days

Information Hiding (Part II)

Implementing a custom collection type in clojure — the leftist heap, a persistent priority queue

A teacup placed on a pile of books

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Donald Raab

Donald Raab

Java Champion. Creator of the Eclipse Collections OSS Java library (http://www.eclipse.org/collections/). Inspired by Smalltalk. Opinions are my own.

More from Medium

Exploring the Smalltalk Collections API in unit tests using Pharo 8.0

An In-Depth Guide to Java Records

Java Reactive Programming: Something Old, Something New

Optional (1) — Coding with Java Optionals!