473,386 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 11016
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 appreciated , i came across udf/udts etc but still not able...
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 to call this method from a javascript it fails on...
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 utilities to do so. Now we evaluate Object...
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. Quick response is appreciated. Thanks, Amit
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 http://pyxida.sourceforge.net/ I initially...
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 like objecttype@12345. But I want to display the...
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 JAXB. I generated XML from User object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.