Package org.eclipse.emf.compare.match.resource

## Class StrategyResourceMatcher

- java.lang.Object
- - org.eclipse.emf.compare.match.resource.StrategyResourceMatcher

All Implemented Interfaces:
  `IResourceMatcher`

    public class StrategyResourceMatcher
    extends Object
    implements IResourceMatcher

A `StrategyResourceMatcher` will be used to match two or three `Resource`s together; depending on whether we are doing a two or three way comparison.

Do take note that the match engine expects ResourceMatchers to return matching resources as well as resources that do not match.

### Field Summary

Fields
`protected Comparator<Resource>` `resourceURIComparator` Compares resources according to the string representation of their `URI`s.

### Constructor Summary

Constructors
`StrategyResourceMatcher()` Default constructor with two strategies: `NameMatchingStrategy` & `RootIDMatchingStrategy`.
`StrategyResourceMatcher​(Collection<IResourceMatchingStrategy> strategies)` Constructor that allows to give your own `IResourceMatchingStrategy`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`protected static boolean` `atLeastTwo​(boolean condition1, boolean condition2, boolean condition3)` This will check that at least two of the three given booleans are `true`.
`Iterable<MatchResource>` `createMappings​(Iterator<? extends Resource> leftResources, Iterator<? extends Resource> rightResources, Iterator<? extends Resource> originResources)` This will be called by the engine in order to retrieve the mappings created by this matcher.
`protected static MatchResource` `createMatchResource​(Resource left, Resource right, Resource origin)` Creates a `MatchResource` instance and sets all three resources of the mapping on it.
`protected IResourceMatchingStrategy[]` `getResourceMatchingStrategies()` Returns the matching strategies that are to be used by this resource matcher.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### resourceURIComparator

    protected Comparator<Resource> resourceURIComparator

Compares resources according to the string representation of their `URI`s.

### Constructor Detail

#### StrategyResourceMatcher

    public StrategyResourceMatcher()

Default constructor with two strategies: `NameMatchingStrategy` & `RootIDMatchingStrategy`.

#### StrategyResourceMatcher

    public StrategyResourceMatcher​(Collection<IResourceMatchingStrategy> strategies)

Constructor that allows to give your own `IResourceMatchingStrategy`.

Parameters:
  `strategies` - the strategies you want to use for the match step. A defensive copy of the provided strategies will be done.

### Method Detail

#### createMappings

    public Iterable<MatchResource> createMappings​(Iterator<? extends Resource> leftResources,
                                                  Iterator<? extends Resource> rightResources,
                                                  Iterator<? extends Resource> originResources)

This will be called by the engine in order to retrieve the mappings created by this matcher.

The returned mappings should include both "matching" resources and "not matching" resources (i.e. resources that are in either left or right ... but not in any of the two other lists).

Specified by:
  `createMappings` in interface `IResourceMatcher`
Parameters:
  `leftResources` - An iterator over the resources we found on the left side.
  `rightResources` - An iterator over the resources we found on the right side.
  `originResources` - An iterator over the resources that may be considered as common ancestors of the couples detected on the left and right sides.
Returns:
  The created resource mappings. Should include both matched and unmatched resources.
See Also:
  `IResourceMatcher.createMappings(java.util.Iterator, java.util.Iterator, java.util.Iterator)`

#### atLeastTwo

    protected static boolean atLeastTwo​(boolean condition1,
                                        boolean condition2,
                                        boolean condition3)

This will check that at least two of the three given booleans are `true`.

Parameters:
  `condition1` - First of the three booleans.
  `condition2` - Second of the three booleans.
  `condition3` - Third of the three booleans.
Returns:
  `true` if at least two of the three given booleans are `true`, `false` otherwise.

#### getResourceMatchingStrategies

    protected IResourceMatchingStrategy[] getResourceMatchingStrategies()

Returns the matching strategies that are to be used by this resource matcher.

This default implementation will try two ways of matching the resources before giving up : resources have equal name, then resources have roots with equal identifiers.

Resource Matching Strategies are expected to map resources together, but not to detect resources that do not match.

Returns:
  The resource matching strategies that should be used by this matcher.

#### createMatchResource

    protected static MatchResource createMatchResource​(Resource left,
                                                       Resource right,
                                                       Resource origin)

Creates a `MatchResource` instance and sets all three resources of the mapping on it.

Parameters:
  `left` - The left resource of this mapping.
  `right` - The right resource of this mapping.
  `origin` - The origin resource of this mapping.
Returns:
  The create mapping.