Thursday, April 10, 2008

Pileated Woodpecker

This Pileated Woodpecker landed on our feeder on April 9, 2008. The apex of the feeder "roof" is 15.5" across, and total height of the feeder is 9.5". How big is it? What is the gender? Let me know what you think! For conparison, an American Crow is 16-20 inches long.

Monday, April 07, 2008

Firing My Own Volley

dangertree techblog has a series entitled "Groovy vs. Google Collections". In Round #1, chief provocateur Matt Taylor sent a devastating salvo of Groovy goodness in my general direction. The problem was to create combinations (dancing pairs) of girls and boys, and then group the dancers by boy and later by girl. I was able to meet the challenge with the help of Multimaps.inverseHashMultimap. I got "thumped" on code size however 37 to 12.

Matt has invited me to initiate Round 2, so now it's my turn.

Let's use a Multimap to associate the makes and models:
Multimap<Make, Model> makeToModel = Multimaps.newHashMultimap();
makeToModel.put(Ford, Taurus);
makeToModel.put(Ford, Focus);
makeToModel.put(Ford, Mustang);
makeToModel.put(Chevrolet, Malibu);
makeToModel.put(Chevrolet, Impala);
makeToModel.put(Chevrolet, Corvette);
makeToModel.put(Dodge, Charger);
makeToModel.put(Dodge, Avenger);
makeToModel.put(Dodge, Viper);
We can look up which models are built by a given make:
Make searchMake = Dodge;
System.out.printf("%s makes ", searchMake);
for (Model model : makeToModel.get(searchMake)) {
System.out.printf("%s,", model);
}
System.out.printf("\n");
The output is: "Dodge makes Viper,Avenger,Charger,"

We can now invert the map:
Multimap<Model, Make> modelToMake = Multimaps.inverseHashMultimap(makeToModel);
And this allows us to do a "reverse" lookup of make by a given model:
Model searchModel = Impala;
System.out.printf("model %s is made by %s\n", searchModel, modelToMake.get(searchModel));
The output is: "model Impala is made by [Chevrolet]"

Note that Make and Model are defined as enumerations. In this way, we can clearly see the difference in expected content between the forward (makeToModel) and inverse (modelToMake) Multimaps. Indeed, the Java compiler will complain if we attempt to put anything other than a Make/Model pair into makeToModel or if we attempt to get() from modelToMake with anything other than a Model.

The complete code is available on Pastie.

Google Collections Java News Brief

Google Collections is my new article published as the April, 2008 OCI Java News Brief.

My previous article for the July, 2004 edition was Improve Java Apps on Windows with a Native Launcher.

Saturday, April 05, 2008

Groovy vs. Google Collections, Round 1

In response to my comment, Matt Taylor challenged me to a "code-off" between Groovy and Google Collections.

Here is my response to his first challenge.

1. Create a set of boys and girls.
Set<String> boys = Sets.newHashSet("Paco", "Sven", "Roger", "Emelio");
Set<String> girls = Sets.newHashSet("Julia", "Prudence", "Lucy");
2. Discover every combination of them.
Multimap<String, String> pairs = combinations(boys, girls);

static Multimap<String, String> combinations(
Set<String> set1, Set<String> set2) {
Multimap<String, String> ret = Multimaps.newHashMultimap();
for (String s1 : set1) {
for (String s2 : set2) {
ret.put(s1, s2);
}
}
return ret;
}

3. Group the combinations by boy and girl.
for (String boy : boys) {
for (String partner : pairs.get(boy)) {
...
}
}

Multimap<String,String> pairsInverse = Multimaps.inverseHashMultimap(pairs);
for (String girl : girls) {
for (String partner : pairsInverse.get(girl)) {
...
}
}

Here is the full source code of the Google Collections version, courtesy Pastie.

Google Collections doesn't provide a combinations function like Groovy does. It would be nice to have the methods combinations(Set<T> ...) and permutations(Set<T> ...) in the Sets utility class.

Friday, November 16, 2007

IntelliJ + SVN Integration

I don't know if this image does it justice, but at the top of the editor, just below the tabs, IntelliJ will put up a yellow strip (reminiscent of Internet Explorer 7) if the file you are working on is out of date, and will display the SVN commit message. It gives you the option to view the diff or update.




Another puck buried in the back of the net for IntelliJ.

Dan

Wednesday, November 14, 2007

IntelliJ IDEA 7.0 Run/Debug Environment Variables

As I mentioned in my previous post, IntelliJ IDEA 7.0 adds support for environment variables in the run/debug dialog:

You put in name=value pairs, separated by the platform path separator. This is good. If you click the ellipsis, you get the following dialog:















Added since M2 is the ability to include the parent environment. This is good! What still doesn't work is the ability to reference the parent environment variables from within dialog. For example, I would like to prepend something to the PATH variable with something like this: PATH=c:\foo;$PATH

This doesn't work. Hopefully the good folks over at Jetbrains will add this feature.













Overall I'm happy with IntelliJ 7.0, mainly for new inspections and little features like the environment variables. Hopefully they will improve this feature in a coming point release.

Monday, September 24, 2007

Eclipse advantages over IntelliJ

Eclipse gives you the capability to set system environment variables, while IntelliJ 6.0.5 does not. It is worth noting that IntelliJ 7M2 does provide that feature, however I've had difficulties being able to override the Path variable by appending to it.

Headbutts and High-Fives

Saturday I ran 22:49 in a local 5K. That
smoked last year's time of 24:07. 5K PB is 20:33, but that was a much
flatter course and it was 2002 and I only weighed 160.

Of course my wife ran a 22:18 and won 1st female overall, six months
after giving birth.

Wednesday, February 28, 2007

From IntelliJ IDEA to Eclipse

I am switching from IntelliJ IDEA 6.0.4 to Eclipse 3.2.2. Both on Windows XP pro.

Here are some of the things I haven't figured out how to do with Eclipse 3.2.2 out of the box.
  1. Tail a log file in a window when running a Java application.
  2. Edit a file using column mode. e.g. select vertical lines of text and edit them.
  3. Format an XML file.
Here are some things I like about Eclipse:
  1. OSGi-based plug-in regime. Nicely documented, and easy enough to do a hello-world. Seperate class loader sandboxes for each plug-in.
  2. Copy-and-run. No hidden registry stuff, no product keys, etc. Just copy your eclipse installation from one computer to another! (And have it running on multiple computers without having multiple licenses, legally)
  3. Drag-and-drop files in and out of the navigation panes in Eclipse to a Windows explorer.