Javarevisited
Published in

Javarevisited

Finding answers to the ultimate questions about Eclipse Collections

What are the most frequently used words in the Eclipse Collections API?

A picture I took from my recent return trip from Florida — Inspired me to think of some questions

Background

I read the Hitchhiker’s Guide to the Galaxy (HHGTTG) Trilogy when I was a teenager in the 1980s. I ran a Bulletin Board System for a couple years and that was when I was first introduced to the books. The books have remained some of my favorites for almost four decades. I often recommend the series to developers I work with.

Deep Thought was a fictional computer in the “Hitchhiker’s Guide to the Galaxy” book series written by Douglas Adams. Deep Thought was built to answer the ultimate question of life, the universe and everything. I highly recommend reading the books if you want to know the answer.

I decided I would build a Java class named DeepThought that could answer all of the ultimate questions I have about methods in the Eclipse Collections API. I started out wanting to know “What is the top preposition?” Then I wanted to know the most frequently referenced iteration pattern, container type, primitive type and mutating verb in the API. I used Eclipse Collections to answer the questions. Thankfully, I didn’t have to wait seven and a half million years for these answers.

Building a Java version of Deep Thought

Here’s a code snapshot of what my Java version of DeepThought does.

The DeepThought Java Class

The process to arrive at the answer to each ultimate question is as follows.

  1. Find all method names in all of the classes in a JAR (Java ARchive)
  2. Flatten all the words in each method name (based on proper case names)
  3. Filter all of the words based on containment in a specified set of of words
  4. Group all of the method names by the matching contained words, and print the top five occurrences of the method names
  5. Find the top occurrence(s) of the specified set of words (The Answer!)

The Answers

I asked DeepThought for answers to the ultimate questions of top prepositions, patterns, types, primitive types, and mutating verbs in the Eclipse Collections API. The code looks separately at the classes in both the eclipse-collections-api-11.1.0.jar (using RichIterable.class) and eclipse-collections-11.1.0.jar (using FastList.class). This code should work with other JAR files as well, as long as they are on the classpath and you reference one of the classes in the JAR. Note: I haven’t tried it with any other JARs, so YMMV.

The Source

Here’s the full source in a gist:

You have to add this class into some package and have a project with the following Maven dependencies in order to get this to work. I used Java 17 and used the var keyword to shorten the code purely for web readability. If you try this in an IDE, you can expand the types if anything isn’t clear.

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-api</artifactId>
<version>11.1.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections</artifactId>
<version>11.1.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.collections</groupId>
<artifactId>eclipse-collections-testutils</artifactId>
<version>11.1.0</version>
<scope>test</scope>
</dependency>

A JLDD Challenge

Maybe José Paumard will find this particular set of problems interesting enough for a JLDD (Jet Lag Driven Development) challenge. The picture I used for this blog was taken on a late evening flight returning from Florida, which was my first flight since February 2020. I am getting inspired for some JLDD challenges for JavaOne in October.

Finding answers to bigger questions

Not all answers have an answer as simple as a single word. Some questions require a deeper understanding and broader view of the world. In HHGTTG, Deep Thought had to commission building an even bigger computer to answer an even more difficult question.

Using visualization can help simplify things for us humans. If you want to build a deeper understanding of Eclipse Collections, then I recommend starting with the following blog. It will help explain why there are so many words in the API that DeepThought has to scan through to come up with the one word answers.

Final Thoughts

I hope you enjoyed this exploration of the Eclipse Collections API. I learned some interesting things as a part of this exercise. I had always wondered how I could programmatically load all of the classes in a JAR. I’m not sure if this is the best way, but it seems to have worked pretty well for my particular experiment. I didn’t want to hard code a reference to a .jar file so discovering this little nugget was interesting.

URL location = clazz.getProtectionDomain().getCodeSource().getLocation();

This allowed me to find a JAR location on the classpath by simply using one of the classes in the JAR. I had never tried this before. Then I was able to use JarFile and JarEntry to get all of the class names and load them. I love when I try random experiments and learn something new and useful.

I hope you enjoyed reading this blog and find the answers to the ultimate questions I had about the Eclipse Collections API at least mildly entertaining.

Thank you for reading! Enjoy!

I am the creator of and a Committer for the Eclipse Collections OSS project which is managed at the Eclipse Foundation. Eclipse Collections is open for contributions.

--

--

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.