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
          Deprecated. 
 
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)
          Deprecated. 
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  java.util.List<org.eclipse.emf.ecore.EObject> getScopeInternalContents(org.eclipse.emf.ecore.EObject eObject, IMatchScope scope)
          Workaround for bug #235606 : elements held by a reference with containment=true and derived=true are not matched since not returned by EObject.eContents().
protected  boolean haveDistinctID(org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right)
          Deprecated. 
protected  boolean haveDistinctXMIID(org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right)
          Deprecated. 
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)
          Deprecated. 
protected  AbstractSimilarityChecker prepareChecker()
          Build the best checker depending on the options.
 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.
protected  void setModelRoots(MatchModel modelRoot, org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right)
          Sets the values of the MatchModel's left and right models.
protected  void setModelRoots(MatchModel modelRoot, org.eclipse.emf.ecore.EObject left, org.eclipse.emf.ecore.EObject right, org.eclipse.emf.ecore.EObject ancestor)
          Sets the values of the MatchModel's left, right and ancestor models.
protected  void updateSettings(MatchSettings settings, java.util.Map<java.lang.String,java.lang.Object> optionMap)
          prepare the engine with the options.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

filter

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


options

@Deprecated
protected java.util.Map<java.lang.String,java.lang.Object> options
Deprecated. 
Contains the options given to the match procedure. This method is deprecated, if you want to handle specific options for your match engine you should override the updateSettings() method.

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)

prepareChecker

protected AbstractSimilarityChecker prepareChecker()
Build the best checker depending on the options.

Since:
1.1

updateSettings

protected void updateSettings(MatchSettings settings,
                              java.util.Map<java.lang.String,java.lang.Object> optionMap)
prepare the engine with the options.

Parameters:
settings - the settings to update.
optionMap - the match options.
Since:
1.1

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)

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

@Deprecated
protected boolean haveDistinctID(org.eclipse.emf.ecore.EObject left,
                                            org.eclipse.emf.ecore.EObject right)
                          throws FactoryException
Deprecated. 

This will lookup in the #matchedByID map and check if the two given objects have indeed been matched by their ID. This method is no more used by the generic match engine implementation itself as this logic moved to the AbstractSimilarityChecker

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

@Deprecated
protected boolean haveDistinctXMIID(org.eclipse.emf.ecore.EObject left,
                                               org.eclipse.emf.ecore.EObject right)
                             throws FactoryException
Deprecated. 

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.

nameSimilarity

@Deprecated
protected double nameSimilarity(org.eclipse.emf.ecore.EObject obj1,
                                           org.eclipse.emf.ecore.EObject obj2)
Deprecated. 

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)

contentSimilarity

@Deprecated
protected double contentSimilarity(org.eclipse.emf.ecore.EObject obj1,
                                              org.eclipse.emf.ecore.EObject obj2)
                            throws FactoryException
Deprecated. 

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)

setModelRoots

protected void setModelRoots(MatchModel modelRoot,
                             org.eclipse.emf.ecore.EObject left,
                             org.eclipse.emf.ecore.EObject right)
Sets the values of the MatchModel's left and right models.

Parameters:
modelRoot - Root of the MatchModel.
left - Element from which to resolve the left model URI.
right - Element from which to resolve the right model URI.
Since:
1.1

setModelRoots

protected void setModelRoots(MatchModel modelRoot,
                             org.eclipse.emf.ecore.EObject left,
                             org.eclipse.emf.ecore.EObject right,
                             org.eclipse.emf.ecore.EObject ancestor)
Sets the values of the MatchModel's left, right and ancestor models.

Parameters:
modelRoot - Root of the MatchModel.
left - Element from which to resolve the left model URI.
right - Element from which to resolve the right model URI.
ancestor - Element from which to resolve the ancestor model URI. Can be null.
Since:
1.1

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.

getScopeInternalContents

protected java.util.List<org.eclipse.emf.ecore.EObject> getScopeInternalContents(org.eclipse.emf.ecore.EObject eObject,
                                                                                 IMatchScope scope)
Workaround for bug #235606 : elements held by a reference with containment=true and derived=true are not matched since not returned by EObject.eContents(). This allows us to return the list of all contents from an EObject including those references.

Parameters:
eObject - The EObject we seek the content of.
scope - The scope to restrict the contents.
Returns:
The list of all the content of a given EObject, derived containmnent references included.
Since:
1.1

Copyright 2006 IBM Corporation and others.
All Rights Reserved.