Skip to main content

A library for diffing java.util.Lists

Posted by timboudreau on May 12, 2009 at 11:18 AM PDT

I recently set up a new project on - this is something that has been available in NetBeans for years, and is probably useful to a wider audience. It is a library for taking two java.util.Lists and generating a diff between them.

There are a number of libraries around that support using Collections as models for Swing components. But most revolve around observable lists, or wrapping lists in observable wrappers.

Siamese Cat style="border-style:solid;border-width:12px;border-color:white;"
But sometimes, you simply don't control the code that is handing you a list. I was in that situation when writing the Navigator for NetBeans 4 — I could get a list of class members, but there was no way to detect changes between them except to compare the previous list I got with the new one.

So I wrote this general-purpose library for generating diffs between lists. It has proven useful in many projects, some not NetBeans-related, so it makes more sense as a project apart from NetBeans.

The main wiki page for the project describes it, and the choices of algorithms available, in detail.

With it, there is also a subproject that implements Swing ListModels, to make it easy to use with JLists (it will be there as soon as I make a build of NB with this bug fixed).


This library has been around for > 5 years. I don't know if either of the projects mentioned in comments above existed then. Regardless, a developer on NetBeans has to jump *huge* legal hurdles with lawyers to add a foreign binary to the NetBeans codebase (intellectual property due diligence). Even if those did exist in 2002, doing a six month process to use one of them was not something I was going to wait for (I'm not saying this is the way it should be, but it is the way it is).

Didn't you first look at commons collections? The class CollectionUtils has a method disjunction that does what you need. Why do we programmers allways have the need to reinvent the wheel even if we can see it with our own eyes?

Did you see/examine java-diff? (