Package org.eclipse.emf.compare.merge

# Class AbstractMerger

java.lang.Object
org.eclipse.emf.compare.merge.AbstractMerger

All Implemented Interfaces:
  `IMergeCriterionAware`, `IMergeOptionAware`, `IMerger`, `IMerger2`

Direct Known Subclasses:
  `AttributeChangeMerger`, `ConflictMerger`, `FeatureMapChangeMerger`, `PseudoConflictMerger`, `ReferenceChangeMerger`, `ResourceAttachmentChangeMerger`, `ResourceLocationChangeMerger`

public abstract class AbstractMerger extends Object implements IMerger2, IMergeOptionAware, IMergeCriterionAware
Abstract implementation of an `IMerger`. This can be used as a base implementation to avoid re-implementing the whole contract.

Since:
  3.0

## Nested Class Summary

## Nested classes/interfaces inherited from interface org.eclipse.emf.compare.merge.IMerger

`IMerger.Registry, IMerger.Registry2, IMerger.RegistryImpl`

## Field Summary

Fields
Modifier and Type
Field
Description
`protected Map<Object,Object>`
`mergeOptions`
The map of all merge options that this merger should be aware of.
`static final String`
`SUB_DIFF_AWARE_OPTION`
The key of the merge option that allows to the mergers to consider sub-diffs of a diff as a whole.

## Constructor Summary

Constructors
Constructor
Description
`AbstractMerger()`
Default constructor.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`accept(Diff diff, boolean rightToLeft)`
Accept the given difference.
`protected <E> void`
`addAt(List<E> list, E value, int insertionIndex)`
Adds the given `value` into the given `list` at the given `index`.
`boolean`
`apply(IMergeCriterion criterion)`
Default implementation of apply for mergers that extends this class.
`protected void`
`copyDiff(Diff target, Monitor monitor, boolean rightToLeft)`
Executes a copy in the given merge direction.
`void`
`copyLeftToRight(Diff target, Monitor monitor)`
Executes the copy from left to right.
`void`
`copyRightToLeft(Diff target, Monitor monitor)`
Executes the copy from right to left.
`protected EObject`
`createCopy(EObject referenceObject)`
This will create a copy of the given EObject that can be used as the target of an addition (or the reverting of a deletion).
`Set<Diff>`
`getDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)`
Retrieves the set of directly required diffs needed in order to merge the current one.
`Set<Diff>`
`getDirectResultingMerges(Diff target, boolean mergeRightToLeft)`
Returns all differences that will be merged because of our merging the given `target` difference.
`Set<Diff>`
`getDirectResultingRejections(Diff target, boolean rightToLeft)`
Returns the set of all differences that need to be rejected if `target` is merged in the given direction.
`protected Set<Diff>`
`getImpliedMerges(Diff target, boolean mergeRightToLeft)`
Returns all differences that are automatically set to the targets `state` if the given target diff is merged.
`protected Set<Diff>`
`getLogicallyResultingMerges(Diff diff, boolean mergeRightToLeft)`
Returns a set of differences that should be logically merged with the given diff.
`Map<Object,Object>`
`getMergeOptions()`
Get the map of options that the merger will have to take into account.
`protected DelegatingMerger`
`getMergerDelegate(Diff diff)`
Find the best merger for diff and wrap it in a delegate that will take the current merge criterion into account.
`static DelegatingMerger`
`getMergerDelegate(Diff diff, IMerger.Registry2 registry, IMergeCriterion criterion)`
Find the best merger for diff and wrap it in a delegate that will take the given merge criterion into account.
`int`
`getRanking()`
Returns the ranking of this merger.
`IMerger.Registry`
`getRegistry()`
Get the registry.
`static boolean`
`isAccepting(Diff diff, boolean mergeRightToLeft)`
Checks whether the given merge direction will result in accepting this difference based on the difference's `source`.
`protected boolean`
`isAdd(ReferenceChange diff, boolean rightToLeft)`
Specifies whether the given `diff` will add a value in the target model for the current merging.
`static boolean`
`isInTerminalState(Diff target)`
Returns whether the given difference is in a terminal state or not.
`protected boolean`
`isSet(ReferenceChange diff, boolean mergeRightToLeft)`
Checks whether the given diff will result in the setting of a reference in the given merge direction.
`protected boolean`
`isUnset(ReferenceChange diff, boolean mergeRightToLeft)`
Checks whether the given diff will result in the unsetting of a reference in the given merge direction.
`protected void`
`mergeDiff(Diff diff, boolean rightToLeft, Monitor monitor)`
This can be used by mergers to merge another (required, equivalent...) difference using the right merger for that diff.
`protected void`
`reject(Diff diff, boolean rightToLeft)`
Reject the given difference.
`void`
`setMergeOptions(Map<Object,Object> options)`
Set the map of options that the merger will have to take into account.
`void`
`setRanking(int r)`
Set the ranking of this merger.
`void`
`setRegistry(IMerger.Registry registry)`
Set the registry containing this merger.

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

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

### Methods inherited from interface org.eclipse.emf.compare.merge.IMerger

`isMergerFor`

## Field Details

### SUB_DIFF_AWARE_OPTION

public static final String SUB_DIFF_AWARE_OPTION
The key of the merge option that allows to the mergers to consider sub-diffs of a diff as a whole.

See Also:
  - Constant Field Values

### mergeOptions

protected Map<Object,Object> mergeOptions
The map of all merge options that this merger should be aware of.

Since:
  3.4

## Constructor Details

### AbstractMerger

public AbstractMerger()
Default constructor.

## Method Details

### getRanking

public int getRanking()
Returns the ranking of this merger.

Specified by:
  `getRanking` in interface `IMerger`
Returns:
  The ranking.
See Also:
  - `IMerger.getRanking()`

### setRanking

public void setRanking(int r)
Set the ranking of this merger.

Specified by:
  `setRanking` in interface `IMerger`
Parameters:
  `r` - The ranking.
See Also:
  - `IMerger.setRanking(int)`

### getRegistry

public IMerger.Registry getRegistry()
Get the registry.

Specified by:
  `getRegistry` in interface `IMerger`
Returns:
  The registry.
See Also:
  - `IMerger.getRegistry()`

### setRegistry

public void setRegistry(IMerger.Registry registry)
Set the registry containing this merger.

Specified by:
  `setRegistry` in interface `IMerger`
Parameters:
  `registry` - The merger registry.
See Also:
  - `IMerger.setRegistry(org.eclipse.emf.compare.merge.IMerger.Registry)`

### apply

public boolean apply(IMergeCriterion criterion)
Default implementation of apply for mergers that extends this class. Will accept `null` or AdditiveMergeCriterion.INSTANCE.

Specified by:
  `apply` in interface `IMergeCriterionAware`
Parameters:
  `criterion` - The merge criterion
Returns:
  `true` if the given criterion is null or is AdditiveMergeCriterion.INSTANCE.
Since:
  3.4

### getMergeOptions

public Map<Object,Object> getMergeOptions()
Get the map of options that the merger will have to take into account.

Specified by:
  `getMergeOptions` in interface `IMergeOptionAware`
Returns:
  the map of options.
See Also:
  - `IMergeOptionAware.getMergeOptions()`

### setMergeOptions

public void setMergeOptions(Map<Object,Object> options)
Set the map of options that the merger will have to take into account.

Specified by:
  `setMergeOptions` in interface `IMergeOptionAware`
Parameters:
  `options` - the map of options.
Since:
  3.3
See Also:
  - `IMergeOptionAware.setMergeOptions(java.util.Map)`

### getDirectMergeDependencies

public Set<Diff> getDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)
Retrieves the set of directly required diffs needed in order to merge the current one. This may includes the diff's `requirements` or any other diff that we need to merge before the given one.

Specified by:
  `getDirectMergeDependencies` in interface `IMerger2`
Parameters:
  `diff` - The diff which direct requirements we need.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  The set of directly required diffs in order to merge the current one.
Since:
  3.2

### getDirectResultingMerges

public Set<Diff> getDirectResultingMerges(Diff target, boolean mergeRightToLeft)
Returns all differences that will be merged because of our merging the given `target` difference. This may include the diff's `implications`, the diff's `equivalences`, the diff's `refinements` or any other diff that we need to merge together with the given diff.

Specified by:
  `getDirectResultingMerges` in interface `IMerger2`
Parameters:
  `target` - The difference we're considering merging.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  The Set of all differences that will be merged because we've merged `target`.
Since:
  3.2

### getDirectResultingRejections

public Set<Diff> getDirectResultingRejections(Diff target, boolean rightToLeft)
Returns the set of all differences that need to be rejected if `target` is merged in the given direction.

Specified by:
  `getDirectResultingRejections` in interface `IMerger2`
Parameters:
  `target` - The difference we're considering merging.
  `rightToLeft` - The direction in which we're considering a merge.
Returns:
  The Set of all differences that will be rejected if we are to merge merged `target`.
Since:
  3.2

### getLogicallyResultingMerges

protected Set<Diff> getLogicallyResultingMerges(Diff diff, boolean mergeRightToLeft)
Returns a set of differences that should be logically merged with the given diff. As opposed to `merge dependencies`, it is not structurally necessary to merge these diffs before the given diff. This may include the diff's `implications`, the diff's `refinement` or any other diff that should be logically merged with the given diff.

Parameters:
  `diff` - The difference we're considering merging.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  The Set of all differences that will be merged because we've merged `diff`.
Since:
  3.5

### getImpliedMerges

protected Set<Diff> getImpliedMerges(Diff target, boolean mergeRightToLeft)
Returns all differences that are automatically set to the targets `state` if the given target diff is merged. This may include the diff's `implications`, the diff's `equivalences` or any other diff that requires no merging by itself.

Parameters:
  `target` - The difference we're considering merging.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  The Set of all differences that will be set to `MERGED` because we've merged `target`.
Since:
  3.5

### copyDiff

protected void copyDiff(Diff target, Monitor monitor, boolean rightToLeft)
Executes a copy in the given merge direction. This method is a generalization of `copyLeftToRight(Diff, Monitor)` and `copyRightToLeft(Diff, Monitor)`.

Parameters:
  `target` - The difference to handle.
  `monitor` - Monitor.
  `rightToLeft` - Merge direction.
Since:
  3.5

### copyLeftToRight

public void copyLeftToRight(Diff target, Monitor monitor)
Executes the copy from left to right.

Specified by:
  `copyLeftToRight` in interface `IMerger`
Parameters:
  `target` - The difference to handle.
  `monitor` - Monitor.
Since:
  3.1
See Also:
  - `IMerger.copyLeftToRight(org.eclipse.emf.compare.Diff, org.eclipse.emf.common.util.Monitor)`

### copyRightToLeft

public void copyRightToLeft(Diff target, Monitor monitor)
Executes the copy from right to left.

Specified by:
  `copyRightToLeft` in interface `IMerger`
Parameters:
  `target` - The difference to handle.
  `monitor` - Monitor.
Since:
  3.1
See Also:
  - `IMerger.copyRightToLeft(org.eclipse.emf.compare.Diff, org.eclipse.emf.common.util.Monitor)`

### accept

protected void accept(Diff diff, boolean rightToLeft)
Accept the given difference. This may be overridden by clients.

Parameters:
  `diff` - the difference to merge
  `rightToLeft` - the direction of the merge
Since:
  3.1

### reject

protected void reject(Diff diff, boolean rightToLeft)
Reject the given difference. This may be overridden by clients.

Parameters:
  `diff` - the difference to merge
  `rightToLeft` - the direction of the merge
Since:
  3.1

### mergeDiff

protected void mergeDiff(Diff diff, boolean rightToLeft, Monitor monitor)
This can be used by mergers to merge another (required, equivalent...) difference using the right merger for that diff.

Parameters:
  `diff` - The diff we need to merge.
  `rightToLeft` - Direction of that merge.
  `monitor` - The monitor we should use to report progress.

### getMergerDelegate

protected DelegatingMerger getMergerDelegate(Diff diff)
Find the best merger for diff and wrap it in a delegate that will take the current merge criterion into account. The current merge criterion should be stored in the merger's mergeOptions map using IMergeCriterion.OPTION_MERGE_CRITERION as a key.

Parameters:
  `diff` - The diff
Returns:
  the best merger to use for merging the diff
Since:
  3.4

### getMergerDelegate

public static DelegatingMerger getMergerDelegate(Diff diff, IMerger.Registry2 registry, IMergeCriterion criterion)
Find the best merger for diff and wrap it in a delegate that will take the given merge criterion into account. This is NOT Thread-safe!

Parameters:
  `diff` - The diff
  `registry` - The registry of mergers where to look for mergers
  `criterion` - The merge criterion to use
Returns:
  The best merger for diff and criterion, wrapped in a delegate to deal with setting/restoring the criterion in the merger used.
Since:
  3.4

### isInTerminalState

public static boolean isInTerminalState(Diff target)
Returns whether the given difference is in a terminal state or not. Differences that are in a terminal state, i.e., either MERGED or DISCARDED, do not need to be handled by the merger.

Parameters:
  `target` - difference
Returns:
  true if the target should be merged, false otherwise.
Since:
  3.5

### isAdd

protected boolean isAdd(ReferenceChange diff, boolean rightToLeft)
Specifies whether the given `diff` will add a value in the target model for the current merging.

To check whether the `diff` is an addition, we have to check the direction of the merge, specified in `rightToLeft` and the `source of the diff`. Therefore, this method delegates to `isLeftAddOrRightDelete(ReferenceChange)` and `isLeftDeleteOrRightAdd(ReferenceChange)`.

Parameters:
  `diff` - The difference to check.
  `rightToLeft` - Direction of the merge.
Returns:
  `true` if `diff` will add a value with this merge, `false` otherwise.
Since:
  3.2

### isUnset

protected boolean isUnset(ReferenceChange diff, boolean mergeRightToLeft)
Checks whether the given diff will result in the unsetting of a reference in the given merge direction.

Parameters:
  `diff` - The difference to check.
  `mergeRightToLeft` - Direction of the merge.
Returns:
  `true` if `diff` will unset a value with this merge, `false` if this will either "set" or "change" values... or if the given diff is affecting a multi-valued reference.

### isSet

protected boolean isSet(ReferenceChange diff, boolean mergeRightToLeft)
Checks whether the given diff will result in the setting of a reference in the given merge direction.

Parameters:
  `diff` - The difference to check.
  `mergeRightToLeft` - Direction of the merge.
Returns:
  `true` if `diff` will set a value with this merge, `false` if this will either "unset" or "change" values... or if the given diff is affecting a multi-valued reference.
Since:
  3.5

### isAccepting

public static boolean isAccepting(Diff diff, boolean mergeRightToLeft)
Checks whether the given merge direction will result in accepting this difference based on the difference's `source`.

                         | LEFT  | RIGHT
     --------------------+-------+-------
     Merge Left to Right | true  | false
     Merge Right to Left | false | true

Parameters:
  `diff` - difference
  `mergeRightToLeft` - merge direction
Returns:
  true if the merge source direction matches the difference source, false otherwise.
Since:
  3.5
See Also:
  - `isRejecting(Diff, boolean)`

### createCopy

protected EObject createCopy(EObject referenceObject)
This will create a copy of the given EObject that can be used as the target of an addition (or the reverting of a deletion).

The target will be self-contained and will have no reference towards any other EObject set (neither containment nor "classic" references). All of its attributes' values will match the given `referenceObject`'s.

Parameters:
  `referenceObject` - The EObject for which we'll create a copy.
Returns:
  A self-contained copy of `referenceObject`.
See Also:
  - `EMFCompareCopier.copy(EObject)`

### addAt

protected <E> void addAt(List<E> list, E value, int insertionIndex)
Adds the given `value` into the given `list` at the given `index`. An `index` lower than zero or greater than the list's size will mean that the value should be appended at the end of the list.

Type Parameters:
  `E` - Type of objects contained in the list.
Parameters:
  `list` - The list into which `value` should be added.
  `value` - The value we need to add to `list`.
  `insertionIndex` - The index at which `value` should be inserted into `list`. `-1` if it should be appended at the end of the list.