472,344 Members | 1,387 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,344 software developers and data experts.

Java Object comparison

Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj
Jul 17 '05 #1
3 10943
You could use the .compareTo method on any object to compare, and all the
objects that are contained within other objects should implement the compare
to method. I.e. all classes that contains objects should override the
compareTo method.

Hope that helped!

~ANDY~
http://www.confusedgeeks.com
"Dheeraj" <dh*******@excite.com> wrote in message
news:29**************************@posting.google.c om...
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj

Jul 17 '05 #2
Implement the Camparable interface, and override the compareTo method.
Then you have to decide how to compare the objects.
fr'instance - if comparing instances of type 'Person' would you consider
salary, height, or weight to decide which is greater-than, less-than, or
equal ??? - its up to the programmer (you) to decide.

"Dheeraj" <dh*******@excite.com> wrote in message
news:29**************************@posting.google.c om...
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.690 / Virus Database: 451 - Release Date: 5/22/2004
Jul 17 '05 #3
implemenet the Compare interface as per specification, thats what it's
for. taking a "short-cut" and doing it, "just this once", is not a
short-cut because it's never just this once

- perry
Dheeraj wrote:
Hi :

I am writing a test utility where i wish to compare two Java objects.
The object consists of many other objects. In other words the objects
tree is deep.

Does anyone one how to compare such objects. I was trying to use Java
refelction to navigate and compare.

Thanks

Dheeraj


Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: sarith sutha | last post by:
Hi Need a help on the above topic, how to pass a java object as parameter to the java stored procedure .Code snippets will be greatly...
2
by: timothy ma and constance lee | last post by:
Do anyone know how to popluate xml file to a java object?
2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying...
0
by: juliane26 | last post by:
Even so it should not be there, it sometimes is: somebody wants to rename a column. Today we do unload / recreate table / load using our own db...
0
by: amitjenny | last post by:
Can anyone povide me the document for db2 object comparison tool frm v2.1 to v3.1 for the db2 v8 mgration. I was not able to find it on internet....
1
by: incunix | last post by:
Trying to run a standalone program I downloaded and know works (I have spoken to the developer on the team etc...). The url where to find it is...
3
by: gurmeetbedi | last post by:
how to save java object into xml from hashtable? any example............
6
by: gjain12 | last post by:
Hi all, I have created a java object that contains some xml tags. When I print it using obj.toString(), it displays some hashed value something...
0
by: kokababu | last post by:
Hi, I have to add xml schema attributes into the java object. Such as, my java object is User. This User object will be represented as XML using...
0
by: concettolabs | last post by:
In today's business world, businesses are increasingly turning to PowerApps to develop custom business applications. PowerApps is a powerful tool...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.