Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Encapsulating HashMap bulding

Reply
Thread Tools

Encapsulating HashMap bulding

 
 
Lew
Guest
Posts: n/a
 
      05-12-2010
Roedy Green writes:
>> Can anyone think of a way to write a method that takes an
>> array of X, and produces a HashMap<Key,X>


Stefan Ram wrote:
> HashMap< Key, X>m( final X[] x ){ return new HashMap< Key, X>(); }


That is genius. This is my favorite answer so far.

Most of the other answers just made my head hurt. I wonder what the point is.
Rephrasing, what is the value?

--
Lew
 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      05-12-2010
On 12 Mai, 06:11, Lew <(E-Mail Removed)> wrote:
> Roedy Green writes:
> >> Can anyone think of a way to write a method that takes an
> >> array of X, and produces a HashMap<Key,X>

> Stefan Ram wrote:
> > HashMap< *Key, X>m( final X[] x ){ return new HashMap< *Key, X>(); }

>
> That is genius. *This is my favorite answer so far.
>
> Most of the other answers just made my head hurt. *I wonder what the point is.
> * Rephrasing, what is the value?


I am sorry your brain hurts.

Actually it did not occur to me that the code above is a valid
implementation of the requirements before. Rereading Roedy's original
posting I think it *is* a valid implementation although I must say
that I found his question a bit vague. So, Roedy, what is it that you
want?

[ ] an empty HashMap with correct types
[ ] a filled HashMap where keys are found based on the values in the
array
[ ] something else, namely
_________________________________
_________________________________

Kind regards

robert
 
Reply With Quote
 
 
 
 
Arne Vajhøj
Guest
Posts: n/a
 
      05-12-2010
On 12-05-2010 00:11, Lew wrote:
> Roedy Green writes:
>>> Can anyone think of a way to write a method that takes an
>>> array of X, and produces a HashMap<Key,X>

>
> Stefan Ram wrote:
>> HashMap< Key, X>m( final X[] x ){ return new HashMap< Key, X>(); }

>
> That is genius. This is my favorite answer so far.


I assume that it was a sarcastic comment on the level of precise
description in Roedy's question.

> Most of the other answers just made my head hurt. I wonder what the
> point is. Rephrasing, what is the value?


The point in Roedy's questions seems very clear to me. He want
to reuse some code for a conversion that he apparently does
frequently.

Arne


 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2010
On Tue, 11 May 2010 02:22:07 -0700 (PDT), Robert Klemme
<(E-Mail Removed)> wrote, quoted or indirectly quoted
someone who said :

>Roedy did not state how exactly the key is obtained for a particular
>value although he seems to insinuate that it's a property of the
>value.


I presumed the key was either a string field in the value or a get
method on the value object for a string. For a somewhat more
difficult problem, allow the key type to be an arbitrary Object of
some generic type.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Beauty is our business.
~ Edsger Wybe Dijkstra (born: 1930-05-11 died: 2002-08-06 at age: 72)

Referring to computer science.
 
Reply With Quote
 
Roedy Green
Guest
Posts: n/a
 
      05-14-2010
On 12 May 2010 03:14:50 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :

>>Can anyone think of a way to write a method that takes an
>>array of X, and produces a HashMap<Key,X>

>
>HashMap< Key, X >m( final X[] x ){ return new HashMap< Key, X >(); }


A lawyer's answer that answers the letter of the spec but not the
spirit.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Beauty is our business.
~ Edsger Wybe Dijkstra (born: 1930-05-11 died: 2002-08-06 at age: 72)

Referring to computer science.
 
Reply With Quote
 
lewis@lewscanon.com
Guest
Posts: n/a
 
      05-15-2010
Roedy Green wrote:
>>>Can anyone think of a way to write a method that takes an
>>>array of X, and produces a HashMap<Key,X>

>


Stefan Ram wrote, quoted or indirectly quoted someone who said :
>>HashMap< Key, X >m( final X[] x ){ return new HashMap< Key, X >(); }

>


Roedy Green wrote:
> A lawyer's answer that answers the letter of the spec but not the
> spirit.
>


That's exactly what makes is so brilliant and funny.

You could, should you have a sense of humor, also call it a comedian's
answer that answers the letter of the spec but not the spirit.

But yeah, there is that nasty precondition.

Shakespeare wrote, "First, we kill all the lawyers" as a recipe for
how to destabilize a society.

--
Lew
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
reuse HashMap$Entry (or HashMap in total) to avoid millions of allocations Vince Darley Java 4 03-02-2010 07:48 AM
java.util.Properties extending from HashMap<Object, Object> insteadof HashMap<String, String> Rakesh Java 10 04-08-2008 04:22 AM
Bulding my first RAID Mastertone Computer Information 1 06-10-2007 04:57 PM
bulding python containing static extension hobel Python 0 09-22-2006 01:32 PM
Bulding python module using C Andrew Degtiariov Python 2 09-24-2004 02:07 PM



Advertisments