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

More new Features w/ Examples

@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);
}
@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);
}
@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());
}
@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);
}
@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);
}
@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);
}
@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

--

--

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