commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: [collections] Composable Map?
Date Wed, 12 Aug 2009 06:43:02 GMT
Is there something wrong with using java.util.Properties? Just do

Properties defaults = new Properties();
.
.
Properties map = new Properties(defaults);

Ralph

On Aug 11, 2009, at 7:01 PM, Christopher Schultz wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> All,
>
> I have a need for the following Map implementation:
>
> Given 2 (or more) source Maps, iteratively fetch the value for a key
> from each of the composed Maps, returning the first non-null value  
> (or,
> at if you prefer, the first value for which the key is set). This is
> intended to work essentially as a Map which can override some default
> values (from a shared Map).
>
> I first tried to use CompositeMap, since it looked like exactly what I
> was looking for. I ended up with an IllegalArgumentException since  
> some
> keys are defined in both Maps. IMO, the class documentation doesn't  
> make
> it clear that the keys most be unique across the source Maps (though  
> the
> documentation for the 2-Map constructor does an exception can be  
> thrown
> if there is a "key collision").
>
> Next I looked at DefaultedMap, but that provides a single default  
> value
> for undefined keys on a single Map.
>
> I poked-around the javadoc but couldn't find anything that looked like
> it fit my needs. Am I missing something? Am I looking for something  
> that
> is so trivial that nobody has bothered writing it?
>
> Yes, I could simply do this:
>
> Map composedMap = new HashMap();
> composedMap.addAll(defaultValuesMap);
> composedMap.addAll(overriddenValuesMap);
>
> ... but what fun is that?
>
> Thanks,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAkqCIn0ACgkQ9CaO5/Lv0PDcJwCdEuvCDXKSnDlwxhmRPJvIQ1F7
> /NAAnR5F7suSDzeo+/bk8616TfagkAp4
> =GS99
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>


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


Mime
View raw message