Learning and beating my head

B

Brian Andrus

I am trying to put together a function (I think in java these are
called methods?) in java that returns a custom type (as defined by a
..jar file I have to import), but I don't know how to set and return
it. I figured out how to read the components of the custom types that
are passed to the function, but now I have to return stuff.

Yeah, I am in over my head, esp since one week ago I hadn't done
anything more than javascript, but if I figure this out, I will have
enough knowledge to know what I am asking for when I ask for a method
to be made.

My declaration for the Method:
public receiveData handleData(DataConfig config,
java.util.Map formData,
double amount,
java.lang.String currencyCode,
java.lang.Integer transactionId,
java.util.Date date)

This is dictated to me, so I cannot change it.
Info about receiveData:

public class receiveData
extends java.lang.Object

Field Summary:
private java.lang.String processId
private java.lang.String userName
private java.lang.String userNumber
private java.lang.String errorMessage
private java.lang.String reference
private java.lang.String response
private boolean success
private boolean again
-----------------------------

so once I have all the receiveData info in variables, how do I return
them as the receiveData data type?


Thanks in advance for any and all help.
If you wish to flame me, relax, it isn't going to help any of us and
just wastes even more bandwidth than just this sad post.

Brian Andrus
batman (at) thundermail (dot) com
 
M

Manolis Wallace

Hi Brian,

I imagine you have already figured out the simple parts of the answer:

receiveData ret = new receiveData();
....
return ret;

in other words, you need to create an object of type receiveData and
return it. The real problem is how to fill the ... part, which is the
part where you load your data into that object. The easy approach of the
type ret.suceess = true; will not work for you, because the fields are
declared as private and thus you do not have access to them. From the
looks of it, almost certainly the receiveData will also have methods
like void setSuccess(boolean success) etc. So you need to run commands
such as ret.setSuccess(true);

For more details on the exact way to create the object and access its
methods you need to look at the API of the jar file (the description of
all the methods and fields in the classes it contains)

I hope this helps,
Manolis
I am trying to put together a function (I think in java these are
called methods?) in java that returns a custom type (as defined by a
.jar file I have to import), but I don't know how to set and return
it. I figured out how to read the components of the custom types that
are passed to the function, but now I have to return stuff.

Yeah, I am in over my head, esp since one week ago I hadn't done
anything more than javascript, but if I figure this out, I will have
enough knowledge to know what I am asking for when I ask for a method
to be made.

My declaration for the Method:
public receiveData handleData(DataConfig config,
java.util.Map formData,
double amount,
java.lang.String currencyCode,
java.lang.Integer transactionId,
java.util.Date date)

This is dictated to me, so I cannot change it.
Info about receiveData:

public class receiveData
extends java.lang.Object

Field Summary:
private java.lang.String processId
private java.lang.String userName
private java.lang.String userNumber
private java.lang.String errorMessage
private java.lang.String reference
private java.lang.String response
private boolean success
private boolean again
-----------------------------

so once I have all the receiveData info in variables, how do I return
them as the receiveData data type?


Thanks in advance for any and all help.
If you wish to flame me, relax, it isn't going to help any of us and
just wastes even more bandwidth than just this sad post.

Brian Andrus
batman (at) thundermail (dot) com


--
Manolis Wallace
http://www.image.ece.ntua.gr/~wallace/
Image, Video & Multimedia Systems Laboratory
Department of Computer Science
School of Electrical & Computer Engineering
National Technical University of Athens
 
E

Erwin Moller

Brian Andrus wrote:

Hi Brain,

Just a friendly advise: Next time post in comp.lang.java.help.
This NG is intended for more advanced topics.
I am trying to put together a function (I think in java these are
called methods?) in java that returns a custom type (as defined by a
.jar file I have to import), but I don't know how to set and return
it.

Hmm,

They are called methods indeed.
A method in Java can return nothing (void) or an object.
What you call 'custom type' is an object (I think).

This object can be anything.

The jar file you talk about is NOT defining anything per se, it is just a
collection of classes (and probably more), in a nice zipped format with
some usefull manifest.

So you need to look up the class-definition in that jarfile and find the
method you are caling, then check it's returntype.
I figured out how to read the components of the custom types that
are passed to the function, but now I have to return stuff.

(they are called arguments passed to the method.)
Yeah, I am in over my head, esp since one week ago I hadn't done
anything more than javascript, but if I figure this out, I will have
enough knowledge to know what I am asking for when I ask for a method
to be made.

My declaration for the Method:
public receiveData handleData(DataConfig config,
java.util.Map formData,
double amount,
java.lang.String currencyCode,
java.lang.Integer transactionId,
java.util.Date date)

This is dictated to me, so I cannot change it.
Info about receiveData:

public class receiveData
extends java.lang.Object

Field Summary:
private java.lang.String processId
private java.lang.String userName
private java.lang.String userNumber
private java.lang.String errorMessage
private java.lang.String reference
private java.lang.String response
private boolean success
private boolean again

The correct answer is: How can I/we answer that question without any
knowledge of this receiveData-object you are talking about?

But that don't help you, does it?

In general:
1) Instantiate a new receiveData in your method handleData(...)
2) possibly do more stuff (like setting variables in your new
receiveData-object)
3) return this new object.

so, something along theese lines:
(In your method handleData)
...............
{
receiveData myFreshReceiveData = new receiveData();

myFreshReceiveData.setXXX(12);
myFreshReceiveData.setYYY("testing");
myFreshReceiveData.setZZZ(currencyCode);

return myFreshReceiveData;
}


As you can see I don't have a clue how to construct a new receiveData, and
which methods it has. Hence my fantasycode.


Thanks in advance for any and all help.

You are welcome.
If you wish to flame me, relax, it isn't going to help any of us and
just wastes even more bandwidth than just this sad post.

No flaming, but I really must warn you that coding Java, coming from
JavaScript, is not going to be easy. You really should get yourself a
decent book and make a good start.
If you are just fiddling around, you'll surely get lost. You need a decent
ground to work from, as we all do.

Good luck.

Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top