473,595 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 11022
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*******@exci te.com> wrote in message
news:29******** *************** ***@posting.goo gle.com...
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*******@exci te.com> wrote in message
news:29******** *************** ***@posting.goo gle.com...
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
6414
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 to achieve the result. Thankx in advance.
2
3672
by: timothy ma and constance lee | last post by:
Do anyone know how to popluate xml file to a java object?
2
6904
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 a type mismatch. It is positively because of the boolean(java primitive)parameter. It goes fine if I change this parameter to int or String. This inteface has a lot more methods which works fine, it is just the
0
1267
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 Comparison to be used for our general admin purposes. Questions: 1) Is it possible to rename columns e.g. using the compare masks; and
0
1147
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
7301
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 downloaded the standalone version and tried to get it working on two nodes after altering the config file but I keep getting the error: "Could not deserialize java object: java.io.StreamCorruptedException: invalid type code: 92" I then decided to...
3
5676
by: gurmeetbedi | last post by:
how to save java object into xml from hashtable? any example............
6
4357
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 exact value that it contains. Does anybody know how to do this? Thanks
0
1776
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 successfully using JAXB. But I want to add xml schema attributes such as <User xmlns="http://testws/rest/schema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
0
7882
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8260
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8250
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6671
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5837
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3908
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1222
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.