|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Convert List to MapHello,
I have the same question as http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E : I need to do a lot of list-to-map conversions, and I'm looking for a way to use commons collections for this. I would like to do something like this: Map map = ListUtils.toMap(list, new SomeTransformerInterface() { void insertIntoMap(Object object, Map map) { SpecificObject s = (SpecificObject) object; map.put(s.getId(), s.getDescription()); } }); Is there a way to do that with commons collection ? Thank you very much |
|
|
Re: Convert List to MapHow is this easier than this:
Map m = new HashMap(); for (SpecificObject x : list) { m.put(s.getId(), s.getDescription()); } ? Why make this soo much harder than it needs to be? On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@...>wrote: > Hello, > > I have the same question as > http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E: > > I need to do a lot of list-to-map conversions, and I'm looking for a way to > use commons collections for this. > I would like to do something like this: > > Map map = ListUtils.toMap(list, new SomeTransformerInterface() { > void insertIntoMap(Object object, Map map) { > SpecificObject s = (SpecificObject) object; > map.put(s.getId(), s.getDescription()); > } > }); > > Is there a way to do that with commons collection ? > > Thank you very much > > > -- Ted Dunning, CTO DeepDyve 111 West Evelyn Ave. Ste. 202 Sunnyvale, CA 94086 http://www.deepdyve.com 858-414-0013 (m) 408-773-0220 (fax) |
|
|
Re : Convert List to MapThanks
Your sample works fine for my use case (that's exactly what I'm doing in my code), but I was wondering about such utility thing just after looking at : http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/TransformedMap.html#decorate(java.util.Map,%20org.apache.commons.collections.Transformer,%20org.apache.commons.collections.Transformer) which is a map-to-map conversions. Since commons-collection provides map-to-map conversion, why does'nt it provide list-to-map conversion with the same logic ? ________________________________ De : Ted Dunning <ted.dunning@...> À : Commons Users List <user@...> Envoyé le : Jeudi, 11 Juin 2009, 23h12mn 10s Objet : Re: Convert List to Map How is this easier than this: Map m = new HashMap(); for (SpecificObject x : list) { m.put(s.getId(), s.getDescription()); } ? Why make this soo much harder than it needs to be? On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@...>wrote: > Hello, > > I have the same question as > http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E: > > I need to do a lot of list-to-map conversions, and I'm looking for a way to > use commons collections for this. > I would like to do something like this: > > Map map = ListUtils.toMap(list, new SomeTransformerInterface() { > void insertIntoMap(Object object, Map map) { > SpecificObject s = (SpecificObject) object; > map.put(s.getId(), s.getDescription()); > } > }); > > Is there a way to do that with commons collection ? > > Thank you very much > > > -- Ted Dunning, CTO DeepDyve 111 West Evelyn Ave. Ste. 202 Sunnyvale, CA 94086 http://www.deepdyve.com 858-414-0013 (m) 408-773-0220 (fax) |
|
|
Re: Re : Convert List to MapWe had a discussion of something like what you're asking for in the past:
http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/<f2e8eedf0709032030s1665dd5g36797577927d221c@...> On Fri, Jun 12, 2009 at 10:55 AM, Adrian Gonzalez<adr_gonzalez@...> wrote: > Thanks > > Your sample works fine for my use case (that's exactly what I'm doing in my code), but I was wondering about such utility thing just after looking at : > http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/TransformedMap.html#decorate(java.util.Map,%20org.apache.commons.collections.Transformer,%20org.apache.commons.collections.Transformer) > which is a map-to-map conversions. > > Since commons-collection provides map-to-map conversion, why does'nt it provide list-to-map conversion with the same logic ? > > > > > > ________________________________ > De : Ted Dunning <ted.dunning@...> > À : Commons Users List <user@...> > Envoyé le : Jeudi, 11 Juin 2009, 23h12mn 10s > Objet : Re: Convert List to Map > > How is this easier than this: > > Map m = new HashMap(); > for (SpecificObject x : list) { > m.put(s.getId(), s.getDescription()); > } > > ? > > Why make this soo much harder than it needs to be? > > On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@...>wrote: > >> Hello, >> >> I have the same question as >> http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E: >> >> I need to do a lot of list-to-map conversions, and I'm looking for a way to >> use commons collections for this. >> I would like to do something like this: >> >> Map map = ListUtils.toMap(list, new SomeTransformerInterface() { >> void insertIntoMap(Object object, Map map) { >> SpecificObject s = (SpecificObject) object; >> map.put(s.getId(), s.getDescription()); >> } >> }); >> >> Is there a way to do that with commons collection ? >> >> Thank you very much >> >> >> > > > > > -- > Ted Dunning, CTO > DeepDyve > > 111 West Evelyn Ave. Ste. 202 > Sunnyvale, CA 94086 > http://www.deepdyve.com > 858-414-0013 (m) > 408-773-0220 (fax) > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re : Re : Convert List to MapThat's exactly what I was talking about !
Has it done its way to commons collection ? (I don't see it in 3.2.1 or in JIRA) Code extract from http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/<f2e8eedf0709032030s1665dd5g36797577927d221c@...> : Map<K,V> CollectionUtils.toMap(Collection<C> input, Transformer<C,K> keyTransformer, Transformer<C,V> valueTransformer, Map<K,V> map) or Map<K,V> CollectionUtils.toMap(Collection<C> input, Transformer<C,K> keyTransformer, Transformer<C,V> valueTransformer) ________________________________ De : James Carman <james@...> À : Commons Users List <user@...> Envoyé le : Vendredi, 12 Juin 2009, 17h27mn 03s Objet : Re: Re : Convert List to Map We had a discussion of something like what you're asking for in the past: http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/<f2e8eedf0709032030s1665dd5g36797577927d221c@...> On Fri, Jun 12, 2009 at 10:55 AM, Adrian Gonzalez<adr_gonzalez@...> wrote: > Thanks > > Your sample works fine for my use case (that's exactly what I'm doing in my code), but I was wondering about such utility thing just after looking at : > http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/TransformedMap.html#decorate(java.util.Map,%20org.apache.commons.collections.Transformer,%20org.apache.commons.collections.Transformer) > which is a map-to-map conversions. > > Since commons-collection provides map-to-map conversion, why does'nt it provide list-to-map conversion with the same logic ? > > > > > > ________________________________ > De : Ted Dunning <ted.dunning@...> > À : Commons Users List <user@...> > Envoyé le : Jeudi, 11 Juin 2009, 23h12mn 10s > Objet : Re: Convert List to Map > > How is this easier than this: > > Map m = new HashMap(); > for (SpecificObject x : list) { > m.put(s.getId(), s.getDescription()); > } > > ? > > Why make this soo much harder than it needs to be? > > On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@...>wrote: > >> Hello, >> >> I have the same question as >> http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E: >> >> I need to do a lot of list-to-map conversions, and I'm looking for a way to >> use commons collections for this. >> I would like to do something like this: >> >> Map map = ListUtils.toMap(list, new SomeTransformerInterface() { >> void insertIntoMap(Object object, Map map) { >> SpecificObject s = (SpecificObject) object; >> map.put(s.getId(), s.getDescription()); >> } >> }); >> >> Is there a way to do that with commons collection ? >> >> Thank you very much >> >> >> > > > > > -- > Ted Dunning, CTO > DeepDyve > > 111 West Evelyn Ave. Ste. 202 > Sunnyvale, CA 94086 > http://www.deepdyve.com > 858-414-0013 (m) > 408-773-0220 (fax) > > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
|
|
Re: Re : Re : Convert List to MapI don't think so, but you're free to copy it if you wish. There's
really not much code there. On Fri, Jun 12, 2009 at 5:56 PM, Adrian Gonzalez<adr_gonzalez@...> wrote: > That's exactly what I was talking about ! > > Has it done its way to commons collection ? (I don't see it in 3.2.1 or in JIRA) > > Code extract from http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/<f2e8eedf0709032030s1665dd5g36797577927d221c@...> : > > Map<K,V> CollectionUtils.toMap(Collection<C> input, > Transformer<C,K> keyTransformer, Transformer<C,V> > valueTransformer, Map<K,V> map) > or > Map<K,V> CollectionUtils.toMap(Collection<C> input, > Transformer<C,K> keyTransformer, Transformer<C,V> > valueTransformer) > > > > > > > > ________________________________ > De : James Carman <james@...> > À : Commons Users List <user@...> > Envoyé le : Vendredi, 12 Juin 2009, 17h27mn 03s > Objet : Re: Re : Convert List to Map > > We had a discussion of something like what you're asking for in the past: > > http://mail-archives.apache.org/mod_mbox/commons-dev/200709.mbox/<f2e8eedf0709032030s1665dd5g36797577927d221c@...> > > > On Fri, Jun 12, 2009 at 10:55 AM, Adrian Gonzalez<adr_gonzalez@...> wrote: >> Thanks >> >> Your sample works fine for my use case (that's exactly what I'm doing in my code), but I was wondering about such utility thing just after looking at : >> http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/TransformedMap.html#decorate(java.util.Map,%20org.apache.commons.collections.Transformer,%20org.apache.commons.collections.Transformer) >> which is a map-to-map conversions. >> >> Since commons-collection provides map-to-map conversion, why does'nt it provide list-to-map conversion with the same logic ? >> >> >> >> >> >> ________________________________ >> De : Ted Dunning <ted.dunning@...> >> À : Commons Users List <user@...> >> Envoyé le : Jeudi, 11 Juin 2009, 23h12mn 10s >> Objet : Re: Convert List to Map >> >> How is this easier than this: >> >> Map m = new HashMap(); >> for (SpecificObject x : list) { >> m.put(s.getId(), s.getDescription()); >> } >> >> ? >> >> Why make this soo much harder than it needs to be? >> >> On Wed, Jun 10, 2009 at 12:19 PM, Adrian Gonzalez <adr_gonzalez@...>wrote: >> >>> Hello, >>> >>> I have the same question as >>> http://mail-archives.apache.org/mod_mbox/commons-user/200509.mbox/%3C878e7290050905002752ed543d@...%3E: >>> >>> I need to do a lot of list-to-map conversions, and I'm looking for a way to >>> use commons collections for this. >>> I would like to do something like this: >>> >>> Map map = ListUtils.toMap(list, new SomeTransformerInterface() { >>> void insertIntoMap(Object object, Map map) { >>> SpecificObject s = (SpecificObject) object; >>> map.put(s.getId(), s.getDescription()); >>> } >>> }); >>> >>> Is there a way to do that with commons collection ? >>> >>> Thank you very much >>> >>> >>> >> >> >> >> >> -- >> Ted Dunning, CTO >> DeepDyve >> >> 111 West Evelyn Ave. Ste. 202 >> Sunnyvale, CA 94086 >> http://www.deepdyve.com >> 858-414-0013 (m) >> 408-773-0220 (fax) >> >> >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@... > For additional commands, e-mail: user-help@... > > > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@... For additional commands, e-mail: user-help@... |
| Free embeddable forum powered by Nabble | Forum Help |