org.eclipse.emf.compare.match.engine
Class GenericMatchEngine

java.lang.Object
  extended by org.eclipse.emf.compare.match.engine.GenericMatchEngine
All Implemented Interfaces:
IMatchEngine

public class GenericMatchEngine
extends java.lang.Object
implements IMatchEngine

These services are useful when one wants to compare models more precisely using the method modelDiff.


Field Summary
protected  MetamodelFilter filter
          MetamodelFilter used for filtering unused features of the objects we're computing the similarity for.
protected  java.util.Map<java.lang.String,java.lang.Object> options
          Contains the options given to the match procedure.
 
Constructor Summary
GenericMatchEngine()
           
 
Method Summary
 MatchModel contentMatch(org.eclipse.emf.ecore.EObject leftObject, org.eclipse.emf.ecore.EObject rightObject, org.eclipse.emf.ecore.EObject ancestor, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method will compare three EObjects and their direct content, ignoring the given objects' siblings and parents for the match.
 MatchModel contentMatch(org.eclipse.emf.ecore.EObject leftObject, org.eclipse.emf.ecore.EObject rightObject, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method will compare two EObjects and their direct content, ignoring the given objects' siblings and parents for the match.
protected  double contentSimilarity(org.eclipse.emf.ecore.EObject obj1, org.eclipse.emf.ecore.EObject obj2)
          This will compute the similarity between two EObjects' contents.
protected  org.eclipse.emf.ecore.EObject findMostSimilar(org.eclipse.emf.ecore.EObject eObj, java.util.List<org.eclipse.emf.ecore.EObject> list)
          This will iterate through the given List and return its element which is most similar (as given by absoluteMetric(EObject, EObject)) to the given EObject.
protected
<T> T
getOption(java.lang.String key)
          This will return the value associated to the given key in the options map.
protected  boolean haveDistinctID(org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right)
          This will lookup in the matchedByID map and check if the two given objects have indeed been matched by their ID.
protected  boolean haveDistinctXMIID(org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right)
          This will lookup in the matchedByXMIID map and check if the two given objects have indeed been matched by their XMI ID.
protected  boolean isSimilar(org.eclipse.emf.ecore.EObject obj1, org.eclipse.emf.ecore.EObject obj2)
          Returns True if the 2 given EObjects are considered similar.
 MatchModel modelMatch(org.eclipse.emf.ecore.EObject leftRoot, org.eclipse.emf.ecore.EObject rightRoot, org.eclipse.emf.ecore.EObject ancestor, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method returns a MatchModel for three models.
 MatchModel modelMatch(org.eclipse.emf.ecore.EObject leftRoot, org.eclipse.emf.ecore.EObject rightRoot, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method returns a MatchModel for two models.
protected  double nameSimilarity(org.eclipse.emf.ecore.EObject obj1, org.eclipse.emf.ecore.EObject obj2)
          This will compute the similarity between two EObjects' names.
 void reset()
          This will be called with each access from the service to the singleton instance of this engine.
 MatchModel resourceMatch(org.eclipse.emf.ecore.resource.Resource leftResource, org.eclipse.emf.ecore.resource.Resource rightResource, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method returns a MatchModel for two resources.
 MatchModel resourceMatch(org.eclipse.emf.ecore.resource.Resource leftResource, org.eclipse.emf.ecore.resource.Resource rightResource, org.eclipse.emf.ecore.resource.Resource ancestorResource, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          This method returns a MatchModel for three resources.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

protected final MetamodelFilter filter
MetamodelFilter used for filtering unused features of the objects we're computing the similarity for.


options

protected final java.util.Map<java.lang.String,java.lang.Object> options
Contains the options given to the match procedure.

Constructor Detail

GenericMatchEngine

public GenericMatchEngine()
Method Detail

contentMatch

public MatchModel contentMatch(org.eclipse.emf.ecore.EObject leftObject,
                               org.eclipse.emf.ecore.EObject rightObject,
                               org.eclipse.emf.ecore.EObject ancestor,
                               java.util.Map<java.lang.String,java.lang.Object> optionMap)
This method will compare three EObjects and their direct content, ignoring the given objects' siblings and parents for the match.

Specified by:
contentMatch in interface IMatchEngine
Parameters:
leftObject - Left of the three objects to get compared.
rightObject - Right of the three objects to compare.
ancestor - Common ancestor of the two others.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
MatchModel for these three objects' comparison.
See Also:
IMatchEngine.contentMatch(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, java.util.Map)

contentMatch

public MatchModel contentMatch(org.eclipse.emf.ecore.EObject leftObject,
                               org.eclipse.emf.ecore.EObject rightObject,
                               java.util.Map<java.lang.String,java.lang.Object> optionMap)
This method will compare two EObjects and their direct content, ignoring the given objects' siblings and parents for the match.

Specified by:
contentMatch in interface IMatchEngine
Parameters:
leftObject - Left of the two objects to get compared.
rightObject - Right of the two objects to compare.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
MatchModel for these two objects' comparison.
See Also:
IMatchEngine.contentMatch(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, java.util.Map)

modelMatch

public MatchModel modelMatch(org.eclipse.emf.ecore.EObject leftRoot,
                             org.eclipse.emf.ecore.EObject rightRoot,
                             org.eclipse.emf.ecore.EObject ancestor,
                             java.util.Map<java.lang.String,java.lang.Object> optionMap)
                      throws java.lang.InterruptedException
This method returns a MatchModel for three models.

Specified by:
modelMatch in interface IMatchEngine
Parameters:
leftRoot - Left model for the comparison.
rightRoot - Right model for the comparison.
ancestor - Common ancestor of the right and left models.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
The corresponding MatchModel.
Throws:
java.lang.InterruptedException - Thrown if the options map specifies a progress monitor, and the comparison gets interrupted somehow.
See Also:
IMatchEngine.modelMatch(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, java.util.Map)

modelMatch

public MatchModel modelMatch(org.eclipse.emf.ecore.EObject leftRoot,
                             org.eclipse.emf.ecore.EObject rightRoot,
                             java.util.Map<java.lang.String,java.lang.Object> optionMap)
                      throws java.lang.InterruptedException
This method returns a MatchModel for two models.

Specified by:
modelMatch in interface IMatchEngine
Parameters:
leftRoot - Left model for the comparison.
rightRoot - Right model for the comparison.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
The corresponding MatchModel.
Throws:
java.lang.InterruptedException - Thrown if the options map specifies a progress monitor, and the comparison gets interrupted somehow.
See Also:
IMatchEngine.modelMatch(org.eclipse.emf.ecore.EObject, org.eclipse.emf.ecore.EObject, java.util.Map)

reset

public void reset()
This will be called with each access from the service to the singleton instance of this engine. Clients should dispose of all caches and recorded information within this method's implementation.

Specified by:
reset in interface IMatchEngine
See Also:
IMatchEngine.reset()

resourceMatch

public MatchModel resourceMatch(org.eclipse.emf.ecore.resource.Resource leftResource,
                                org.eclipse.emf.ecore.resource.Resource rightResource,
                                java.util.Map<java.lang.String,java.lang.Object> optionMap)
                         throws java.lang.InterruptedException
This method returns a MatchModel for two resources.

Specified by:
resourceMatch in interface IMatchEngine
Parameters:
leftResource - Left compared resource.
rightResource - Right compared resource.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
The corresponding MatchModel.
Throws:
java.lang.InterruptedException - Thrown if the options map specifies a progress monitor, and the comparison gets interrupted somehow.
See Also:
IMatchEngine.resourceMatch(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.resource.Resource, java.util.Map)

resourceMatch

public MatchModel resourceMatch(org.eclipse.emf.ecore.resource.Resource leftResource,
                                org.eclipse.emf.ecore.resource.Resource rightResource,
                                org.eclipse.emf.ecore.resource.Resource ancestorResource,
                                java.util.Map<java.lang.String,java.lang.Object> optionMap)
                         throws java.lang.InterruptedException
This method returns a MatchModel for three resources.

Specified by:
resourceMatch in interface IMatchEngine
Parameters:
leftResource - Left compared resource.
rightResource - Right compared resource.
ancestorResource - Common ancestor of the two compared resources.
optionMap - Options to tweak the matching procedure. null or Collections.EMPTY_MAP will result in the default options to be used.
Returns:
The corresponding MatchModel.
Throws:
java.lang.InterruptedException - Thrown if the options map specifies a progress monitor, and the comparison gets interrupted somehow.
See Also:
IMatchEngine.resourceMatch(org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.resource.Resource, org.eclipse.emf.ecore.resource.Resource, java.util.Map)

contentSimilarity

protected double contentSimilarity(org.eclipse.emf.ecore.EObject obj1,
                                   org.eclipse.emf.ecore.EObject obj2)
                            throws FactoryException
This will compute the similarity between two EObjects' contents.

Parameters:
obj1 - First of the two EObjects.
obj2 - Second of the two EObjects.
Returns:
double representing the similarity between the two EObjects' contents. 0 < value < 1.
Throws:
FactoryException - Thrown if we cannot compute the EObjects' contents similarity metrics.
See Also:
NameSimilarity.contentValue(EObject, MetamodelFilter)

findMostSimilar

protected org.eclipse.emf.ecore.EObject findMostSimilar(org.eclipse.emf.ecore.EObject eObj,
                                                        java.util.List<org.eclipse.emf.ecore.EObject> list)
                                                 throws FactoryException
This will iterate through the given List and return its element which is most similar (as given by absoluteMetric(EObject, EObject)) to the given EObject.

Parameters:
eObj - EObject we're searching a similar item for in the list.
list - List in which we are to find an object similar to eObj.
Returns:
The element from list which is the most similar to eObj.
Throws:
FactoryException - Thrown if we cannot compute the absolute metric between eObj and one of the list's objects.

getOption

protected <T> T getOption(java.lang.String key)
               throws java.lang.ClassCastException
This will return the value associated to the given key in the options map.

NOTE : Misuses of this method will easily throw ClassCastExceptions.

Type Parameters:
T - Expected type of the value associated to key.
Parameters:
key - Key of the value to retrieve.
Returns:
Value associated to the given key in the options map.
Throws:
java.lang.ClassCastException - If the value isn't assignment compatible with the expected type.

haveDistinctID

protected boolean haveDistinctID(org.eclipse.emf.ecore.EObject left,
                                 org.eclipse.emf.ecore.EObject right)
                          throws FactoryException
This will lookup in the matchedByID map and check if the two given objects have indeed been matched by their ID.

Parameters:
left - Left of the two objects to check.
right - Right of the two objects to check.
Returns:
True these objects haven't been matched by their ID, False otherwise.
Throws:
FactoryException - Thrown if we cannot compute the key for the object to match.

haveDistinctXMIID

protected boolean haveDistinctXMIID(org.eclipse.emf.ecore.EObject left,
                                    org.eclipse.emf.ecore.EObject right)
                             throws FactoryException
This will lookup in the matchedByXMIID map and check if the two given objects have indeed been matched by their XMI ID.

Parameters:
left - Left of the two objects to check.
right - Right of the two objects to check.
Returns:
True these objects haven't been matched by their XMI ID, False otherwise.
Throws:
FactoryException - Thrown if we cannot compute the key for the object to match.

isSimilar

protected boolean isSimilar(org.eclipse.emf.ecore.EObject obj1,
                            org.eclipse.emf.ecore.EObject obj2)
                     throws FactoryException
Returns True if the 2 given EObjects are considered similar.

Parameters:
obj1 - The first EObject to compare.
obj2 - Second of the EObjects to compare.
Returns:
True if both elements have the same serialization ID, False otherwise.
Throws:
FactoryException - Thrown if we cannot compute one of the needed similarity.

nameSimilarity

protected double nameSimilarity(org.eclipse.emf.ecore.EObject obj1,
                                org.eclipse.emf.ecore.EObject obj2)
This will compute the similarity between two EObjects' names.

Parameters:
obj1 - First of the two EObjects.
obj2 - Second of the two EObjects.
Returns:
double representing the similarity between the two EObjects' names. 0 < value < 1.
See Also:
NameSimilarity.nameSimilarityMetric(String, String)

Copyright 2006 IBM Corporation and others.
All Rights Reserved.