org.eclipse.emf.ecore.util
Class EcoreUtil.EqualityHelper

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<EObject,EObject>
          extended by org.eclipse.emf.ecore.util.EcoreUtil.EqualityHelper
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.util.Map<EObject,EObject>
Enclosing class:
EcoreUtil

public static class EcoreUtil.EqualityHelper
extends java.util.HashMap<EObject,EObject>

A helper for determining whether two EObjects are structurally equal. Two EObjects, eObject1 and eObject2, are structurally equal if their classes are the same, and if, for each non-derived feature of the class, the isSet states are the same and the corresponding values are structurally equal as appropriate for the type of feature. For feature map features, the entries at corresponding positions must have the same entry features and must have structurally equal values as appropriate for the type of entry's feature. For reference features, the corresponding values must recursively be structurally equal according to this definition. For attribute features, the corresponding values must be equal according to Java equality. Note that container references are derived and hence are ignored.

During the recursive process of determining equality, the helper instance is populated as a two way map such that a given eObject1 is considered to be equal to at most one other eObject2, i.e., get(eObject1) == eObject2 && get(eObject2) == eObject1. While their features are being compared, the two objects are assumed to be equal:

 
  put(eObject1, eObject2); 
  put(eObject2, eObject1);
Once that correspondence is established, an eObject1 considered equal to a different eObject2 will not even be considered equal to itself. This ensures that two objects are structurally equal only if the graphs formed by all their referenced objects have the same topology.

See Also:
EcoreUtil.equals(EObject, EObject), equals(EObject, EObject), Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
EcoreUtil.EqualityHelper()
           
 
Method Summary
protected  boolean equalFeatureMaps(FeatureMap featureMap1, FeatureMap featureMap2)
          Returns whether the two feature maps are equal.
protected  boolean equalFeatureMapValues(java.lang.Object value1, java.lang.Object value2, EStructuralFeature feature)
          Returns whether the two values of a feature map are equal.
 boolean equals(EObject eObject1, EObject eObject2)
          Returns whether eObject1 and eObject2 are equal in the context of this helper instance.
 boolean equals(java.util.List<EObject> list1, java.util.List<EObject> list2)
          Returns whether list1 and list2 contain equal EObjects at the same index.
protected  boolean haveEqualAttribute(EObject eObject1, EObject eObject2, EAttribute attribute)
          Returns whether the two objects have equal values for the attribute.
protected  boolean haveEqualFeature(EObject eObject1, EObject eObject2, EStructuralFeature feature)
          Returns whether the two objects have equal isSet states and values for the feature.
protected  boolean haveEqualReference(EObject eObject1, EObject eObject2, EReference reference)
          Returns whether the two objects have equal values for the reference.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, put, putAll, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

EcoreUtil.EqualityHelper

public EcoreUtil.EqualityHelper()
Method Detail

equals

public boolean equals(EObject eObject1,
                      EObject eObject2)
Returns whether eObject1 and eObject2 are equal in the context of this helper instance.

Returns:
whether eObject1 and eObject2 are equal.
Since:
2.1.0

equals

public boolean equals(java.util.List<EObject> list1,
                      java.util.List<EObject> list2)
Returns whether list1 and list2 contain equal EObjects at the same index. It is assumed that list1 and list2 only contain EObjects.

Returns:
whether list1 and list2 contain equal objects.
Since:
2.1.0

haveEqualFeature

protected boolean haveEqualFeature(EObject eObject1,
                                   EObject eObject2,
                                   EStructuralFeature feature)
Returns whether the two objects have equal isSet states and values for the feature.

Returns:
whether the two objects have equal isSet states and values for the feature.
Since:
2.2.0
See Also:
equals(EObject, EObject), equals(List, List)

haveEqualReference

protected boolean haveEqualReference(EObject eObject1,
                                     EObject eObject2,
                                     EReference reference)
Returns whether the two objects have equal values for the reference.

Returns:
whether the two objects have equal values for the reference.
Since:
2.1.0
See Also:
equals(EObject, EObject), equals(List, List)

haveEqualAttribute

protected boolean haveEqualAttribute(EObject eObject1,
                                     EObject eObject2,
                                     EAttribute attribute)
Returns whether the two objects have equal values for the attribute.

Returns:
whether the two objects have equal values for the attribute.
Since:
2.1.0
See Also:
equalFeatureMaps(FeatureMap, FeatureMap)

equalFeatureMaps

protected boolean equalFeatureMaps(FeatureMap featureMap1,
                                   FeatureMap featureMap2)
Returns whether the two feature maps are equal.

Returns:
whether the two feature maps are equal.
Since:
2.1.0

equalFeatureMapValues

protected boolean equalFeatureMapValues(java.lang.Object value1,
                                        java.lang.Object value2,
                                        EStructuralFeature feature)
Returns whether the two values of a feature map are equal.

Returns:
whether the two values of a feature map are equal.
Since:
2.2.0

Copyright 2001-2006 IBM Corporation and others.
All Rights Reserved.