You need to describe what you mean by Object and what you mean by comparison. for instance is the comparison simply a question of checking for existence of an id/key or do you need to compare every attribute between them to detect synchronisation issues.
If dealing with a complex structure that has to be identical you would need a java service that goes through each attribute of one of the objects, checking if it exists in the other and comparing values. However, do you want to then check in the opposite direction, in case there are attributes in the other that aren’t in the former.
Find an example here, paste the static methods below into the shared area of java service and then call it
boolean isSame = compare(doc1, doc2);
It assumes that your inputs are documents i.e. IData and that you only have well behaved types in your structure i.e. IData, IData or any base java type as an array or instance.
regards,
John.
// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
private static boolean compare(IData doc1, IData doc2) {
boolean fail = false;
if (doc2 != null) {
if (doc1 != null) {
IDataCursor d1 = doc1.getCursor();
IDataCursor d2 = doc2.getCursor();
d1.first();
do {
String key = d1.getKey();
Object origValue = d1.getValue();
Object compareValue = IDataUtil.get(d2, key);
if (compareValue != null && compareValue.getClass().equals(origValue.getClass())) {
fail = comparator(origValue, compareValue);
} else {
fail = true;
}
// no match and no point continuing
if (fail) {
break;
}
} while (d1.next());
d2.destroy();
d1.destroy();
} else {
fail = true;
}
} else {
fail = true;
}
return !fail;
}
private static boolean comparator(Object origValue, Object compareValue) {
boolean fail = false;
if (origValue instanceof IData) {
fail = compare((IData) origValue, (IData) compareValue);
} else if (origValue instanceof IData[]) {
IData[] origValueArray = (IData[]) origValue;
IData[] compareValueArray = (IData[]) compareValue;
if (origValueArray.length == compareValueArray.length) {
for (Object oi : origValueArray) {
// scan other array from start to beginning, break out when we find match
boolean gotOne = false;
for (Object ci: compareValueArray) {
if (comparator(oi, ci)) {
gotOne = true;
break;
}
}
// no match found, break out of loop, return fail
if (!gotOne) {
fail = true;
break;
}
}
}
} else {
fail = !origValue.equals(compareValue);
}
return !fail;
}
// --- <<IS-END-SHARED-SOURCE-AREA>> ---
#Integration-Server-and-ESB#webMethods#webMethods-io-Integration