
h1. Adapting the comparison process

@Author@ Me
@Contact@ me@mycompany.com

{toc}

h2. Introduction

If you defined your own formalism using an @ecore@ model you might want to control the way your model is processed during the comparison to get results faster or to avoid false positives.
The main things you'll want to customize is the match process, it's responsability is to match elements from both versions of the models, trying to determine their identity. 

h2. Customizing the Match Engine

You first need to write your own @IMatchEngine@ , the simplest way to do so is to extends the @GenericMatchEngine@ which already provides all the needed behavior and plugin in your own customized @SimilarityChecker@

pre.. 

public class LibraryMatchEngine extends GenericMatchEngine {

	@Override
	protected AbstractSimilarityChecker prepareChecker() {
		return new AbstractSimilarityChecker(filter) {

			/**
			 * Should determine whether an element is similar to the other one or not.
			 * 
			 * @param obj1
			 *            an element.
			 * @param obj2
			 *            another element.
			 * @return true if those elements have the same identity.
			 */
			@Override
			public boolean isSimilar(EObject obj1, EObject obj2) throws FactoryException {
				// TODO Auto-generated method stub
				return false;
			}

			@Override
			public double absoluteMetric(EObject obj1, EObject obj2) throws FactoryException {
				// TODO Auto-generated method stub
				return 0;
			}

			@Override
			public void init(Resource leftResource, Resource rightResource) throws FactoryException {
				// TODO Auto-generated method stub

			}

			@Override
			public void init(EObject leftObject, EObject rightObject) throws FactoryException {
				// TODO Auto-generated method stub

			}

		};
	}
  
p. 
And then you can specify your own similarity logic redefining the isSimilar method. Please note that you'll have to express a distance between two elements through the @absoluteMetric(...)@ method. 
The @init(...)@ methods will be called by the match engine so that you can prepare your matching process if you need to.

bq.. 
  If your matching process is *able* to return, right away, from a given instance it's matched counter part, then you should override the @fastLookup(..)@ method to return this instance :

pre.. 

	@Override
	public EObject fastLookup(EObject obj1) {
		return leftToRight.get(obj1);
	}

p. 
It is not mandatory and only here to get a faster processing with specific matching like, for instance, ID based ones.
Please have a look on the existing @AbstractSimilarityChecker@ subclasses and feel free to copy/paste from those, these are not provided through the API yet but will have API counterparts at some point.