views:

171

answers:

3

I've inherited a team and a (Java) code base.

The code base makes use of a lot of explicit for each loops. I'd like to replace those (edit: in future code) with something like Commons Collections Transformers and Predicates and its collect and transform methods.

However, Commons Collection isn't generic. The rest of my code base, whatever else it lacks, is, and I don't want to introduce a lot of casting.

So I'm looking at the Commons-Collections with Generics (http://sourceforge.net/projects/collections/) and at Guava (formerly Google Collections) (http://code.google.com/p/guava-libraries/).

Question one: is either or both of those libraries Generally Recognized As Safe for production use? Do you use either in production?

Question two: of the two, which do you recommend? Answers from anyone who has used either are great, answers from anyone who has used both even better!

Finally, my team includes a mix of contractors who are mid- to senior-level, and employees who are mid- and junior-level in Java (edit: but with multi-year experience in non-OO programming) . So I don't want to introduce more than one collections library, and I do want one that won't be too hard for any of my team to use.

Thanks!

Edit: I want to replace explicit loops because the amount of boilerplate obscures and overwhelms the actual business code. I've got nested loops calling functions with nested loops, all to do things that are one-liners. With the proper introduction and training, I feel my team will find a Collections/Transformer/Predicate approach cleaner, clearer, faster to write, and easier to read.

+3  A: 

I use Google collections in production and have never had a problem. Makes you wish java had function pointers, but he design is well thought out. Even he little things like Lists.newArrayList become the.standard way to new up a list.

Nathan Feger
"Makes you wish Java had function pointers". Java 8. Fingers crossed.
Thilo
@Thilo: maybe Java 10. Just maybe.
Matt Ball
JDK7 (now 8, I guess) "includes a new package, java.dyn, that contains the classes associated with dynamic language support in the Java platform. One of the classes in the package is MethodHandle. A method handle is a simple object of type java.dyn.MethodHandle that anonymously encapsulates a reference to a JVM method. A method handle is callable, just like a named reference to a method." http://www.oracle.com/technetwork/issue-archive/2010/10-may/o30java-099612.html
Thilo
@Thilo: I'm pretty sure `MethodHandle` and friends are going to be in JDK7. But I don't know that there's going to be a lot of use for them in Java itself until JDK8 when lambdas and method references are added. Initially, I think it'll mostly be used for dynamic languages on the JVM.
ColinD
+2  A: 

It seems that you are not looking for a Collection library, but rather a library for working with existing collections in a functionnal way.

I wrote such a library myself, but it is not open source (it is only used internally in my company), and it may not be the best designed one.

A library with the same goal seems promising : lambdaj. I haven't used it myself, but I think I wouldn't have written my library if I was aware of the existence of lambdaj, at that time.

barjak
+1  A: 

I suggest to give a look at lambdaj either. Here you can find an overview of the main features: http://code.google.com/p/lambdaj/wiki/LambdajFeatures

Mario Fusco