× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Perhaps I am not understanding what the Java code does. When I write this in Java:

HashMap reportParameters = new HashMap();
reportParameters.put("selectName", "BALL");



I understand it to mean that I create a new HashMap object called "reportParameters". It is basically a container into which I can put key/value pairs. So, after creating a new "empty" object, I add the key/value pair I want to assign using "put". The Java code I have above works. So, I based my RPG code on the same (or, that was what I was *trying* to do).

It is very possible that I created the Java and corresponding RPG prototypes incorrectly or with incorrect understanding. I couldn't find an example of an RPG wrapper that instantiated an object and then called a method that modified the contents of that instantiated object. In the Java example above, the method call modifies the object. Do you have an example of an RPG wrapper that does something similar?

You said:

"Since you just created the hashmap *immediately* before calling the
'put' method, I think it's safe to assume that there's nothing assigned
to any of the keys in the hashmap -- that being the case, 'null' is the
*expected* return value."

That is true. So after creating the object I immediately assign the key/value pair to it with the call to rre_jMap_put method which I supposed was correct. What did I miss?

The assignment of the key/value pairs is what I am after so this

lReParam = new_jMap();

is supposed to create the object, and this code:

lkey = new_String('selectName');
lvalue = new_String('BALL');
lReParam = rre_jMap_put(lReParam:lkey:lvalue);

is supposed to take that object and add the key/value pair "'selectName','BALL'" to the object. I expected lReParam to have the key/value pair 'selectName','BALL" assigned to it after I called the procedure. It doesn't. The values are null.

What did I miss? When you said that I didn't check the return value, are you saying that I didn't check lReParam object value after I constructed it to make sure I had a valid reference or that I failed to check the lReParam value after I called the "put" method? Based on the debugging I put into the Java code, it appears that I have a valid jMap object after calling new_jMap(). What I don't get is a valid key/value pair added to that object after I call the rre_jMap_put method which I find out by iterating through the key/value pairs in the object in a later call. That later call is in a wrapped private Java method that basically println's the values to the console. When I run the Java code directly, it will output the key/value pairs if I have assigned values and it will out "Value is null" if I instantiate the object and assign no key/value pairs to it. When I call the same code from my RPG wrapped procedures, I get "Value is Null" output to the console. I am assuming that the rre_jMap_put method failed to add the key/value pair. I guess that assumption could be wrong and that the code is broken further downstream.

So, based on what you see, you think that after the lReParam = rre_jMap_put(lReParam:lkey:lvalue); line has executed, the lReParam object *should* have the key/value pairs I added. If so, I'll look at the remaining code to see if I passed a null value rather than the actual object.

Pete



Scott Klement wrote:
Hi Pete,

According to the JavaDocs for java.util.HashMap, the 'put' method is supposed to return the object that was previously assigned to the key, or else it should return null if no object was previously assigned to the key.

I'm looking at these Javadocs:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/HashMap.html

Since you just created the hashmap *immediately* before calling the 'put' method, I think it's safe to assume that there's nothing assigned to any of the keys in the hashmap -- that being the case, 'null' is the *expected* return value.

So I guess I don't understand what the issue is?

Your message implies that the Java code doesn't do the same thing -- but the Java code that you demonstrated doesn't even attempt to check the return value!

Obviously, there's additional code in your application that I haven't seen, so maybe I'm missing the point. Can you show the code that's returning a null when it shouldn't be?


Pete Helgren wrote:
I have been puzzling over how to wrap the HashMap put method. I successfully (I thought) built prototypes, interfaces and an RPG wrapper to handle the call, but I must be doing something wrong because it is not working. It is returning a null value.

Java Prototypes:

*+++++++++++++++++++++++++++++++
* new_jMap
* Create a new Java Hashmap object
*
* Returns the new Java HashMap object
*+++++++++++++++++++++++++++++++
D new_jMap...
D PR like(jMap)
D ExtProc(*JAVA
D :'java.util.HashMap'
D :*CONSTRUCTOR)
*++++++++++++++++++++++++++++++
* jMap_put
* Add a key and a value to a hashmap
*
*++++++++++++++++++++++++++++++
D JMAP_put...
D PR like(jObject)
D EXTPROC(*JAVA
D :'java.util.HashMap'
D :'put')
D key like(jObject)
D value like(jObject)

And the RPG wrapper prototype:

D rre_jMap_put...
D PR like(jObject)
D prMap like(jMap)
D prKey like(jObject)
D prValue like(jObject)
RPG Wrapper program:
*-------------------------------------------
* Add elements to a Hashmap
*
*-------------------------------------------
P rre_jMap_put...
P B EXPORT
D rre_jMap_put...
D PI like(jObject)
D peMap like(jMap)
D peKey like(jobject)
D peValue like(jObject)
D

/free

peMap = JMAP_put(peMap:peKey:peValue);

return peMap;

/End-free
P E

Finally when I call it in my program (relevant code):

lReParam = new_jMap();
lkey = new_String('selectName');
lvalue = new_String('BALL');
lReParam = rre_jMap_put(lReParam:lkey:lvalue);

The thing that I am uncertain about is that when I code in Java, I act on the object directly rather than passing it back and forth (it may be a shorthand way, I don't know). So in Java I would do this:

HashMap reportParameters = new HashMap();
reportParameters.put("selectName", "BALL");

But even changing the RPG code above to this:

lReParam = new_jMap();
lkey = new_String('selectName');
lvalue = new_String('BALL');
rre_jMap_put(lReParam:lkey:lvalue);

Has the same result which is a null value for the key/value pair.

I am missing something. Any suggestions?
Thanks,

Pete




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.