Suppose you want to create a copy of the ImmutableSet / List / Map object, but filter out some of the source records. One way to implement this:
ImmutableList.copyOf(Iterables.filter(myObject, myObject.EQUALS));
where myObject.EQUALS is the predicate for the Iterables.filter() operation. I think this is a pretty elegant and readable implementation. However, one builds two list objects (first through a call to Iterables.filter(...) , the second through ImmutableList.copyOf(...) ), which is very inefficient.
Does anyone know a more efficient way to do this?
I think it would be best to add filter predicates to the ImmutableSet / List / Map constructors so that the object is created only once. But, unfortunately, there is no such parameter.
java performance immutability guava
danbim May 30 '11 at 13:29 2011-05-30 13:29
source share