Map<?, ?> rightMap = (Map<?, ?>) right;
// Create copy from which we can remove elements.
Map<Object, Object> rightCopy = new HashMap<Object, Object>(rightMap);
ReflectionComparator keyReflectionComparator = createRefectionComparator();
MapDifference difference = new MapDifference("Different elements", left, right, leftMap, rightMap);
for (Map.Entry<?, ?> leftEntry : leftMap.entrySet()) {
Object leftKey = leftEntry.getKey();
Object leftValue = leftEntry.getValue();
boolean found = false;
Iterator<Map.Entry<Object, Object>> rightIterator = rightCopy.entrySet().iterator();
while (rightIterator.hasNext()) {
Map.Entry<Object, Object> rightEntry = rightIterator.next();
Object rightKey = rightEntry.getKey();
Object rightValue = rightEntry.getValue();
// compare keys using strict reflection compare
boolean isKeyEqual = keyReflectionComparator.isEqual(leftKey, rightKey);
if (isKeyEqual) {
found = true;
rightIterator.remove();
// compare values