On 5 Aug 2008, at 14:42, Jason T. Greene wrote:
>>
>> What I would like to do, provided everyone is ok with this, is
>> switch this code to static factory methods like so:
>>
>> Immutables.immutableCopy(Map map);
>> Immutables.immutableCopy(List list);
>> Immutables.immutableCopy(Set set);
>>
>> These will then just call clone and Collections.unmodifiableXXX as
>> appropriate. We can then add optimizations later if they become
>> available.
> Would these be more generic, to suit any collection
> implementation? Remember that not all Maps, for example, implement
> Cloneable or have a copy constructor. And wrapping any Map passed
> in as a FastCopyHashMap may break correctness, for example, if a
> SortedMap were passed in.
Right, they would use instanceof to check all the known map types as
a fast-path optimization. After that it would check for cloneable,
and use reflection to invoke clone. It would then look for a copy
constructor, and failing that it would then create a different
collection type. We could for example, in the case of a non-copyable
SortedMap, use a TreeMap, and order is maintained.
Right yes, you would need the logic in place to do this.
--
Manik Surtani
Lead, JBoss Cache
manik(a)jboss.org