New ways to create Maps in Eclipse Collections Map API

Neha Sardana
2 min readDec 4, 2020
Top view of the city of Copenhagen, Denmark taken in 2012

Eclipse Collections provide a way to create both Mutable and Immutable Map with its rich Map API. Recently I worked on Eclipse Collections creating new methods on both MutableMap and ImmutableMap.

Eclipse Collections already has MutableMap.withMap method which allows merging a MutableMap with any JDK Map and returns a MutableMap. I contributed a similar method ImmutableMap.newWithMap to ImmutableMap API. I also added ImmutableMap.newWithMapIterable method so that a user can merge any MapIterable type which includes MutableMap and ImmutableMap as well. The new methods return a new ImmutableMap because it is created only once and it does not have a put method to allow any modifications. To maintain symmetry with the MutableMap, I added MutableMap.withMapIterable and MutableMap.putAllMapIterable methods. The link to my Pull Request is here.

How to create new Map Instances?

ImmutableMap.newWithMap

ImmutableMap.newWithMapIterable

MutableMap.withMapIterable

MutableMap.putAllMapIterable

The new APIs methods will be available in the next release of EC (11.0.0).

Learning from contribution to OSS

  • After I added the two new methods to the MutableMapIterable interface and two methods to ImmutableMapIterable interface, I started getting a lot of compilation errors, so I started tracing down the path to fix those compilations down the hierarchy. I thought it was very cool.
  • I made these four implementations using four commits in a Pull request. In order to manage and keep the history aligned, I created a lot of local branches. I had amazing learning experience using Git rebase, cherry-picking, squash and many more.
  • I worked with passionate developers in this project and always found someone helping me out when I felt stuck. To me, it was very important because I was new to contribute to OSS.
  • I also found some of the blogs below to be very useful. Do check them out!

More resources on Eclipse Collections

Happy Coding and Happy Learning!

I am a software developer, traveller, blogger, yogi and cricket lover. If you like any of these topics, here is my twitter link @nehasardana09 and linkedIn page to connect.

--

--