commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Henri Yandell <bay...@generationjava.com>
Subject Re: [collections] Collections Next Gen
Date Wed, 02 Apr 2003 18:15:52 GMT


On Wed, 2 Apr 2003, Alex Chaffee / Purple Technology wrote:

> Yet another option is to put the static creation methods on the class
> itself:
>
>   Map fooMap = FooMap.createFooMapFor(sourceMap);

If the class itself is viewable, then this is fine. It seems the usual
view is to hide the SynchronizingMap which lives behind
MapUtils.synchronizedMap(Map) etc.  [not a real example]



> that you can't add methods to an interface.  Since ProxyMap is not an
> interface, we don't have this limitation.

ProxyMap's just an abstract. The methods themselves would be on children
of ProxyMap.

> If you want, you could put the creation methods on MapUtils also, and
> have one static call the other.
>
>     public static Map fixedSizeMap(Map map) {
>         return FixedSizeMap.createFixedSizeMapFor(map);
>     }
>

> Then FixedSizeMap et al. could be promoted from inner to normal public
> classes.

I think this is mainly a style. The current Collections way allows the
implementors to hide the fact that MapUtils.fixedSizeMap may not really
use an underlying FixedSizeMap class. It's defensive API tactics.

> Also, AFAICT, ProxyMap is only ever useful if you subclass it
> (otherwise you'd just use the original map).  Since it thus doesn't
> need any public constructors, I see no problem with a protected (not
> package!) constructor that has non-standard semantics, as long as any
> public ctors are copy constructors like the Collections API says.
>
> (BTW, I'm confused by your example -- SequencedMap is not a ProxyMap...)

It should be :) I want to be able to make a sequenced tree map without
coding my own, and I also want a sequenced multi hash map.

I think the documentation for Collections should talk in terms of features
and not classes. ie) Commons-Collections provides the following features:

              Map                Set          List
ordered        y                  n            -
sequenced      y                  n            -
unique         y                  -            n

etc. Accessing said feature would be through the MapUtils class at all
times. Then people can quite easily learn the API by just using the
feature matrix to work out just what is possible.

There would be a separate piece of documentation which would discuss
replacements for HashMap, LinkedList etc, but I believe these are the
exceptions and not the common case.

Hen



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message