Question
· Apr 3, 2018

Comparing Cache-Objects

Hi guys,

is there an easy way to compare two objects in os?

Example:

I have a registered order-object at runtime. Now I want to call a specific export-service just in the case that sth in this order has changed since the last export. So I have to compare the persisted order-object (last export) with the current order-object.

Ist there an easy way to compare these two objects or do I have to check each object-value separately?

Thanks for your help!

Regards, Thomas

Discussion (1)0
Log in or sign up to continue

If you want to compare two in-memory objects, you can use method generators, there are several related articles and discussions on that:

Simple comparator on GiitHib - note that it's a runtime comparator, therefore slow. Better solution would be method generators.

If you're comparing objects of different classes you need to find their common ancestor class and compare using that.

If you're comparing stored objects you can calculate hashes and compare that.

All in all it's a very complex topic and you need to determine what requirements do you have:

  • Streams?
  • Lists? Arrays? Position change?
  • Loops/relationships strategy
  • How many levels to compare?
  • Different classes? Do they have common superclass?
  • Do you need to compare dynamic objects/objects from unrelated classes?

And design your comparator based on that.

Here's a simple hasher on GitHub.