Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   A HashMap isn't storing all of the entries. (http://www.velocityreviews.com/forums/t955178-a-hashmap-isnt-storing-all-of-the-entries.html)

Stryder 12-05-2012 11:29 PM

A HashMap isn't storing all of the entries.
 
I'm doing this...

HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;
devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});

but it's dropping the first entry. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...

java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

Any help is appreciated. Thanks.

Stryder 12-05-2012 11:37 PM

Re: A HashMap isn't storing all of the entries.
 
On Wednesday, December 5, 2012 6:29:23 PM UTC-5, Stryder wrote:
> I'm doing this...
>
>
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
>
> devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
>
> devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
>
> devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
>
> devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;
>
> devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});
>
>
>
> but it's dropping the first entry. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...
>
>
>
> java version "1.7.0_03"
>
> Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
>
> Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)
>
>
>
> Any help is appreciated. Thanks.


I got it to work by increasing the initial number of entries in the HashMap constructor, so the question is pretty much academic unless I encounter it again. But I'd be interested if anyone knows the answer.

Daniele Futtorovic 12-05-2012 11:48 PM

Re: A HashMap isn't storing all of the entries.
 
On 06/12/2012 00:29, Stryder allegedly wrote:
> I'm doing this...
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
> devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
> devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
> devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
> devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;
> devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});
>
> but it's dropping the first entry.


I'll bet 50 that it isn't actually dropping it, or that the reason for
it lies in code residing outside of the java.* hierarchy.

--
DF.

Lew 12-06-2012 12:05 AM

Re: A HashMap isn't storing all of the entries.
 
Daniele Futtorovic wrote:
> Stryder allegedly wrote:
>> I'm doing this...
>>
>> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);


Why do you declare it with an initial capacity of 5? That seems strikingly pointless.

Why do you declare the variable as 'HashMap' rather than 'Map'?

>> devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
>> devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
>> devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
>> devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;
>> devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});
>>
>> but it's dropping the first entry.


Wrong. It's not doing that. You are.

> I'll bet 50� that it isn't actually dropping it, or that the reason for
> it lies in code residing outside of the java.* hierarchy.


I wouldn't take that bet, because you're almost certainly correct.

We won't know exactly where the problem is until the OP deigns to provide a
http://sscce.org/

>> I got it to work by increasing the initial number of entries in the HashMap constructor,


Wrong again. Also, why 5? What's wrong with 16?

By starting the map at 5 buckets and giving it 5 entries, you guaranteed atleast one
growth cycle for the map. The load factor by default is 0.75, so you reallyshould have at least
8 buckets for 5 entries.

You do realize that 'HashMap' increases size automatically, right, and it doesn't drop
entries when it does so? Your data loss has nothing to do with the initial capacity of the
map.

>> so the question is pretty much academic unless I encounter it again.
>> But I'd be interested if anyone knows the answer.


PEBKAC.

Give us an SSCCE or give up on knowing what you did wrong.

By the way, 'devObjectMap' is a very unsatisfactory variable name.

--
Lew

Eric Sosman 12-06-2012 02:07 AM

Re: A HashMap isn't storing all of the entries.
 
On 12/5/2012 6:29 PM, Stryder wrote:
> I'm doing this...
>
> HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);
> devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});
> devObjectMap.put("Email", new String[] {"ADLN","DRLN"});
> devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});
> devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;
> devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});
>
> but it's dropping the first entry. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...


Your "verification" is wrong, with 99.44% probability. Could you
provide an SSCCE? Here's mine:

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class Foo {
public static void main(String[] unused) {
HashMap<String, String[]> devObjectMap = new HashMap<String,
String[]>(5);
devObjectMap.put("DataExtension", new String[]{"ADLN_Customer",
"ADLN_Story"});
devObjectMap.put("Email", new String[]{"ADLN", "DRLN"});
devObjectMap.put("EmailSendDefinition", new String[]{"ADLN",
"AILR"});
devObjectMap.put("ImportDefinition", new
String[]{"ADLN_Customer", "ADLN_Story", "AILR_Customer"});
devObjectMap.put("ContentArea", new String[]{"All_Subject_Lines",
"Date_issue"});

for (Map.Entry<String, String[]> me : devObjectMap.entrySet()) {
System.out.printf("\"%s\" -> %s%n", me.getKey(),
Arrays.toString(me.getValue()));
}
}
}

.... and the output is:

run:
"ContentArea" -> [All_Subject_Lines, Date_issue]
"DataExtension" -> [ADLN_Customer, ADLN_Story]
"EmailSendDefinition" -> [ADLN, AILR]
"Email" -> [ADLN, DRLN]
"ImportDefinition" -> [ADLN_Customer, ADLN_Story, AILR_Customer]
BUILD SUCCESSFUL (total time: 0 seconds)

--
Eric Sosman
esosman@comcast-dot-net.invalid

Stryder 12-06-2012 01:09 PM

Re: A HashMap isn't storing all of the entries.
 
Thanks for your help, Eric, my verification was wrong. Lew, rude as he was, was correct, it was a dumb mistake on my part. That being said, this is my first intro to SSCCE, a valuable concept.

On Wednesday, December 5, 2012 9:07:13 PM UTC-5, Eric Sosman wrote:
> On 12/5/2012 6:29 PM, Stryder wrote:
>
> > I'm doing this...

>
> >

>
> > HashMap<String, String[]> devObjectMap = new HashMap<String, String[]>(5);

>
> > devObjectMap.put("DataExtension", new String[] {"ADLN_Customer","ADLN_Story"});

>
> > devObjectMap.put("Email", new String[] {"ADLN","DRLN"});

>
> > devObjectMap.put("EmailSendDefinition", new String[] {"ADLN","AILR"});

>
> > devObjectMap.put("ImportDefinition", new String[] {"ADLN_Customer","ADLN_Story","AILR_Customer"}) ;

>
> > devObjectMap.put("ContentArea", new String[] {"All_Subject_Lines","Date_issue"});

>
> >

>
> > but it's dropping the first entry. I verified in this case that the "DataExtension" entry was missing but the others were there. It's always the first entry I "put" that disappears. Here's the output of java -version...

>
>
>
> Your "verification" is wrong, with 99.44% probability. Could you
>
> provide an SSCCE? Here's mine:
>
>
>
> import java.util.Arrays;
>
> import java.util.HashMap;
>
> import java.util.Map;
>
> public class Foo {
>
> public static void main(String[] unused) {
>
> HashMap<String, String[]> devObjectMap = new HashMap<String,
>
> String[]>(5);
>
> devObjectMap.put("DataExtension", new String[]{"ADLN_Customer",
>
> "ADLN_Story"});
>
> devObjectMap.put("Email", new String[]{"ADLN", "DRLN"});
>
> devObjectMap.put("EmailSendDefinition", new String[]{"ADLN",
>
> "AILR"});
>
> devObjectMap.put("ImportDefinition", new
>
> String[]{"ADLN_Customer", "ADLN_Story", "AILR_Customer"});
>
> devObjectMap.put("ContentArea", new String[]{"All_Subject_Lines",
>
> "Date_issue"});
>
>
>
> for (Map.Entry<String, String[]> me : devObjectMap.entrySet()) {
>
> System.out.printf("\"%s\" -> %s%n", me.getKey(),
>
> Arrays.toString(me.getValue()));
>
> }
>
> }
>
> }
>
>
>
> ... and the output is:
>
>
>
> run:
>
> "ContentArea" -> [All_Subject_Lines, Date_issue]
>
> "DataExtension" -> [ADLN_Customer, ADLN_Story]
>
> "EmailSendDefinition" -> [ADLN, AILR]
>
> "Email" -> [ADLN, DRLN]
>
> "ImportDefinition" -> [ADLN_Customer, ADLN_Story, AILR_Customer]
>
> BUILD SUCCESSFUL (total time: 0 seconds)
>
>
>
> --
>
> Eric Sosman
>
> esosman@comcast-dot-net.invalid


Lew 12-06-2012 06:54 PM

Re: A HashMap isn't storing all of the entries.
 
Stryder wrote:
> Thanks for your help, Eric, my verification was wrong. Lew, rude as he was, was correct,


Oooh! A value judgment!

You point me to anything I told you that was not strictly factually correct and
in any way denigrated you, and I'll grant you your off-point accusation.

Your code indicated that you had not thoroughly (granting you a lot) read
the Javadocs for map implementations.

This is a "teach a person to fish" arena. I hope for your sake you don't fall into
the trap of whining when things aren't fed you on a silver spoon with fawning,
obsequious fooferol to make it more palatable. **** or stay off the pot.

--
Lew

John B. Matthews 12-06-2012 07:22 PM

Re: A HashMap isn't storing all of the entries.
 
In article <cda45a45-462f-4eb8-8db9-c37443a43191@googlegroups.com>,
Stryder <stryder100@gmail.com> wrote:

> On Wednesday, December 5, 2012 6:29:23 PM UTC-5, Stryder wrote:
> [...]
> I got it to work by increasing the initial number of entries in the
> HashMap constructor, so the question is pretty much academic unless I
> encounter it again. But I'd be interested if anyone knows the answer.


If the problem abated after reducing latency in growing the Map, one
might suspect a data race. If your Map is used to construct a Swing
component model, for example, you should rule out this common fault:

<http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

Daniele Futtorovic 12-07-2012 02:50 AM

Re: A HashMap isn't storing all of the entries.
 
On 06/12/2012 14:09, Stryder allegedly wrote:
>> Your "verification" is wrong, with 99.44% probability.
>>

> Thanks for your help, Eric, my verification was wrong. (...) it was a dumb mistake on my part.


Dammit! Couldn't you have show just a bit more pig-headedness and taken
my bet?! ;o)

For your edification, my (serious) willingness to bet didn't arise from
some blind faith in teh Jav, but rather from experience, that is from
the numerous cases where I, too, thought teh Jav was failing me, only to
make the humbling realisation that it was actually my very own failing.
I'll venture to say that Eric's 99.44% number came from similar sources.

PS: on Usenet, it is common to post your replies /below/ that to which
you respond to.

Cheers,

--
DF.

Eric Sosman 12-07-2012 04:46 AM

Re: A HashMap isn't storing all of the entries.
 
On 12/6/2012 9:50 PM, Daniele Futtorovic wrote:
> [...]
> I'll venture to say that Eric's 99.44% number came from similar sources.


Specifically, <http://tinyurl.com/b8uedkt>.

87.3% of quoted statistics are made up out of thin air.

For politicians, it's 103.6%.

--
Eric Sosman
esosman@comcast-dot-net.invalid


All times are GMT. The time now is 08:07 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.