Finding answers to the ultimate questions about Eclipse Collections
What are the most frequently used words in the Eclipse Collections API?
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
The process to arrive at the answer to each ultimate question is as follows.
- Find all method names in all of the classes in a JAR (Java ARchive)
- Flatten all the words in each method name (based on proper case names)
- Filter all of the words based on containment in a specified set of of words
- Group all of the method names by the matching contained words, and print the top five occurrences of the method names
- Find the top occurrence(s) of the specified set of words (The Answer!)
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
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.
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.
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.
Visualizing Eclipse Collections
A visual overview of the APIs, Interfaces, Factories, Static Utility and Adapters in Eclipse Collections using mind…
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
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!