Whose Desk Is It Anyway?

One thing that annoyed me to no end at my job at VIP Traders was the large stack of paperwork with apparently no corresponding folder to put it into. Then I discovered that hidden away in everyone’s desk is a pile of folders that have slipped through the cracks and do not get filed away in the normal filing system. Because these random stacks of folders lacked any sort of organization, checking every piece of paperwork against every folder in everyone’s desk would be a massive undertaking. For a human anyway.

So I decided to make a computer do it for me.

I immediately started work on a simple database client which I called “Whose Desk Is It Anyway?” which would keep a list of all ID’s of the paperwork in the stack of paperwork I couldn’t find, and of all of the ID’s of the folders in peoples desks, and let me know which papers need to go to whose desk.

For the sake of simplicity, I used SQLite (Xerial) and stored the .db file on a network drive so my coworker and I could use the program simultaneously.

As we began using it, I began to flesh out the UX by adding convenience features.

I integrated the program with the companies old Lotus Approach database so we could verify information about the paperwork while we added it to our program.
I added import and export features so that a list of stock numbers generated in one of the other programs I wrote could be added or deleted from a location in this programs database easily.

This is by far one of the most personally useful projects I’ve ever done, making what I do at my job so much easier. It has been instrumental in finding a home for all the orphaned paperwork.


The SQL database uses a simple two column table, relating location (TABLE_NAME) to paperwork ID (VIN).
The program finds matches using a simple SQL query:

SELECT VIN FROM FOLDERS GROUP BY VIN HAVING COUNT(TABLE_NAME) >= 2;

The results from the query are loaded into a HashMap<String, ArrayList<String>> and fed into my favorite snippet of code from this project.

I needed to sort the result set by first sorting each Array in the HashMap, and then sorting the HashMap based on the first element in each sorted Array. Thanks to Java 8, I managed to do it in 4 lines.

ArrayList<map.entry<string, arraylist="">&gt; results = new ArrayList&lt;&gt;(resultsMap.entrySet());
results.sort(Comparator.comparing(o -&gt; {
o.getValue().sort(String.CASE_INSENSITIVE_ORDER);
return o.getValue().get(0);
}));
</map.entry<string,>

This code first converts the HashMap to an ArrayList of entries and uses the built in sort method with a generated Comparator which is configured to sort the inner Array (using the built in sort method, and a default Comparator from String) and return its first element for comparison. The performance impact from repeatedly sorting the Array was not noticeable, since the HashMap I am dealing with here usually only contains ~20 strings with about 2 to 4 elements in each Array.

Source Code