Jaggregate version 3.3

What is Jaggregate?

Jaggregate is a collections library that is modeled after the ANSI Smalltalk collection protocols, as described here [PDF].

Why write another collections library when Sun's Java already has one?

The author of Jaggregate has been ruined by Smalltalk and Ruby. In those languages and environments, everything really is an object, and (at least in Smalltalk, and mostly in Ruby) a program does work by sending messages to objects. Smalltalk in fact has no native syntax for such concepts as:

So the way to perform common enumerative tasks on collections is to send messages such as #select:, #detect:, #collect:, #reject:, like so:

|numbers evenFinder evens odds firstEven nearestEvens| numbers := OrderedCollection with: 1 with: 2 with: 3. evenFinder := [:anInteger | anInteger \\ 2 = 0]. evens := numbers select: evenFinder. odds := numbers reject: evenFinder. firstEven := numbers detect: evenFinder. nearestEvens := numbers collect: [:each | each \\ 2 = 0 ifTrue: [each] ifFalse: [each + 1]]. numbers = (1 .. 3) evenFinder = proc { |i| i % 2 == 0 } evens = numbers.select &evenFinder odds = numbers.reject &evenFinder firstEven = numbers.detect &evenFinder nearestEvens = numbers.collect { |i| i % 2 == 0 ? i : i + 1 }

Neat, huh? Nice and clean.

Now consider typical Java Collections Framework (JCF) idioms for accomplishing these tasks (being generous and collapsing loops where possible):

List<Integer> numbers = new ArrayList<Integer>(); numbers.add( 1 ); numbers.add( 2 ); numbers.add( 3 ); List<Integer> evens = new ArrayList<Integer>(); List<Integer> odds = new ArrayList<Integer>(); int firstEven; boolean foundAnEven = false; List<Integer> nearestEvens = new ArrayList<Integer>(); for ( Integer next : numbers ) { if ( next % 2 == 0 ) { evens.add( next ); if ( !foundAnEven ) { firstEven = next; foundAnEven = true; } nearestEvens.add( next ); } else { odds.add( next ); nearestEvens.add( next + 1 ); } }

The JCF filled a void in the core of the library that previously only commercial software vendors had filled. Nevertheless, the JCF sports some bothersome features:

I'm not here to knock the JCF; but it does have some limitations.

Jaggregate in Contrast to JCF

Jaggregate benefits from the following:

Let's be honest here: It's a reasonably safe bet that Jaggregate will not overtake the JCF in popularity or mindshare. You can probably live with its limitations, and fill whatever gaps you need to with Jakarta Commons Collections and the like. This project is partly an experiment in Java 5, partly a pining for more of a Smalltalk-ish "objects do it themselves" model. But hopefully, you'll be interested enough to give it a try. Perhaps you'll learn something about Java generics, or be motivated to try out "everything is an object" languages such as Smalltalk or Ruby.

I'd love to hear your feedback!