org.eclipse.emf.compare.merge

## Class CachingDiffRelationshipComputer

- java.lang.Object
- - org.eclipse.emf.compare.merge.CachingDiffRelationshipComputer

All Implemented Interfaces:
  IDiffRelationshipComputer

    public class CachingDiffRelationshipComputer
    extends Object
    implements IDiffRelationshipComputer

A computer implementation to cache the relationship of diffs.

Since:
  3.5
See Also:
  `IMerger2`

### Field Summary

Fields
`protected Map<Diff,Set<Diff>>` `allResultingMergesL2R` All resulting merges: left to right.
`protected Map<Diff,Set<Diff>>` `allResultingMergesR2L` All resulting merges: right to left.
`protected Map<Diff,Set<Diff>>` `allResultingRejectionsL2R` All resulting rejections: left to right.
`protected Map<Diff,Set<Diff>>` `allResultingRejectionsR2L` All resulting rejections: right to left.
`protected IDiffRelationshipComputer` `computer` A computer instance to calculate the relationships between diffs.
`protected Map<Diff,Set<Diff>>` `directMergeDependenciesL2R` Direct merge dependencies: left to right.
`protected Map<Diff,Set<Diff>>` `directMergeDependenciesR2L` Direct merge dependencies: right to left.
`protected Map<Diff,Set<Diff>>` `directResultingMergesL2R` Direct resulting merges: left to right.
`protected Map<Diff,Set<Diff>>` `directResultingMergesR2L` Direct resulting merges: right to left.
`protected Map<Diff,Set<Diff>>` `directResultingRejectionsL2R` Direct resulting rejections: left to right.
`protected Map<Diff,Set<Diff>>` `directResultingRejectionsR2L` Direct resulting rejections: right to left.

### Constructor Summary

Constructors
Constructor and Description
`CachingDiffRelationshipComputer(IDiffRelationshipComputer computer)` Creates a new computer by wrapping the given instance.
`CachingDiffRelationshipComputer(IMerger.Registry registry)` Creates a new computer with the given registry.
`CachingDiffRelationshipComputer(IMerger.Registry registry, IMergeCriterion criterion)` Creates a new computer with the given registry and merge criterion.

### Method Summary

All Methods Instance Methods Concrete Methods
`protected Set<Diff>` `computeAllResultingMerges(Diff diff, boolean mergeRightToLeft)` Computes all resulting merges for the given diff.
`protected Set<Diff>` `computeAllResultingRejections(Diff diff, boolean mergeRightToLeft)` Computes all resulting rejections for the given diff.
`protected Set<Diff>` `computeDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)` Computes direct merge dependencies for the given diff.
`protected Set<Diff>` `computeDirectResultingMerges(Diff diff, boolean mergeRightToLeft)` Computes direct resulting merges for the given diff.
`protected Set<Diff>` `computeDirectResultingRejections(Diff diff, boolean mergeRightToLeft)` Computes the direct resulting rejections.
`Set<Diff>` `getAllResultingMerges(Diff diff, boolean mergeRightToLeft)` Returns the cached direct resulting merges, if present.
`Set<Diff>` `getAllResultingRejections(Diff diff, boolean mergeRightToLeft)` Retrieves the set of all diffs that will be rejected if the given `diff` is merged, either because of unresolveable conflicts or because of unreachable requirements.
`protected Set<Diff>` `getCachedAllResultingMerges(Diff diff, boolean mergeRightToLeft)` Returns the cached all resulting merges.
`protected Set<Diff>` `getCachedAllResultingRejections(Diff diff, boolean mergeRightToLeft)` Returns the cached all resulting rejections.
`protected Set<Diff>` `getCachedDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)` Returns the cached direct merge dependencies.
`protected Set<Diff>` `getCachedDirectResultingMerges(Diff diff, boolean mergeRightToLeft)` Returns the cached direct resulting merges.
`protected Set<Diff>` `getCachedDirectResultingRejections(Diff diff, boolean mergeRightToLeft)` Returns the cached direct resulting rejections.
`protected IDiffRelationshipComputer` `getComputer()` Returns the internal computer instance used to compute the diff relationships.
`Set<Diff>` `getDirectMergeDependencies(Diff diff, boolean mergeRightToLeft)` Returns the cached direct merge dependencies, if present.
`Set<Diff>` `getDirectResultingMerges(Diff diff, boolean mergeRightToLeft)` Returns the cached direct resulting merges, if present.
`Set<Diff>` `getDirectResultingRejections(Diff diff, boolean mergeRightToLeft)` Returns the set of all differences that need to be rejected if `diff` is merged in the given direction.
`IMergeCriterion` `getMergeCriterion()` Returns the merge criterion considered for calculating the diff relationships.
`IMerger2` `getMerger(Diff diff)` Returns the best-fitting merger for the given diff according to the `merger registry` and the `merge criterion`.
`IMerger.Registry` `getMergerRegistry()` Returns the merger registry used for calculating the diff relationships.
`boolean` `hasMerger(Diff diff)` Indicates whether a best-fitting merger for the given diff is available.
`void` `invalidate()` Invalidates the complete cache, so that relationships will be re-calculated any diff the next time a respective method is called.
`void` `invalidate(Diff diff)` Invalidates the cache for the given diff, so that relationships will be re-calculated for this diff the next time a respective method is called.
`void` `invalidate(Iterable<Diff> diffs)` Invalidates the cache for all given diffs, so that relationships will be re-calculated for each diff the next time a respective method is called.
`protected void` `setCachedAllResultingMerges(Diff diff, boolean mergeRightToLeft, Set<Diff> allResultingMerges)` Caches the given all resulting merges.
`protected void` `setCachedAllResultingRejections(Diff diff, boolean mergeRightToLeft, Set<Diff> allResultingRejections)` Caches the given all resulting rejections.
`protected void` `setCachedDirectMergeDependencies(Diff diff, boolean mergeRightToLeft, Set<Diff> directMergeDependencies)` Caches the given direct merge dependencies.
`protected void` `setCachedDirectResultingMerges(Diff diff, boolean mergeRightToLeft, Set<Diff> directResultingMerges)` Caches the given direct resulting merges.
`protected void` `setCachedDirectResultingRejections(Diff diff, boolean mergeRightToLeft, Set<Diff> directResultingRejections)` Caches the given direct resulting rejections.
`void` `setMergeCriterion(IMergeCriterion mergeCriterion)` Sets the merge criterion considered for calculating the diff relationships.
`void` `setMergerRegistry(IMerger.Registry mergerRegistry)` Sets the merger registry used for calculating the diff relationships.

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

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

### Field Detail

#### computer

    protected IDiffRelationshipComputer computer

A computer instance to calculate the relationships between diffs.

#### directMergeDependenciesR2L

    protected Map<Diff,Set<Diff>> directMergeDependenciesR2L

Direct merge dependencies: right to left.

#### directMergeDependenciesL2R

    protected Map<Diff,Set<Diff>> directMergeDependenciesL2R

Direct merge dependencies: left to right.

#### directResultingMergesR2L

    protected Map<Diff,Set<Diff>> directResultingMergesR2L

Direct resulting merges: right to left.

#### directResultingMergesL2R

    protected Map<Diff,Set<Diff>> directResultingMergesL2R

Direct resulting merges: left to right.

#### directResultingRejectionsR2L

    protected Map<Diff,Set<Diff>> directResultingRejectionsR2L

Direct resulting rejections: right to left.

#### directResultingRejectionsL2R

    protected Map<Diff,Set<Diff>> directResultingRejectionsL2R

Direct resulting rejections: left to right.

#### allResultingMergesR2L

    protected Map<Diff,Set<Diff>> allResultingMergesR2L

All resulting merges: right to left.

#### allResultingMergesL2R

    protected Map<Diff,Set<Diff>> allResultingMergesL2R

All resulting merges: left to right.

#### allResultingRejectionsR2L

    protected Map<Diff,Set<Diff>> allResultingRejectionsR2L

All resulting rejections: right to left.

#### allResultingRejectionsL2R

    protected Map<Diff,Set<Diff>> allResultingRejectionsL2R

All resulting rejections: left to right.

### Constructor Detail

#### CachingDiffRelationshipComputer

    public CachingDiffRelationshipComputer(IMerger.Registry registry)

Creates a new computer with the given registry.

Parameters:
  `registry` - merger registry

#### CachingDiffRelationshipComputer

    public CachingDiffRelationshipComputer(IMerger.Registry registry,
                                           IMergeCriterion criterion)

Creates a new computer with the given registry and merge criterion.

Parameters:
  `registry` - merger registry
  `criterion` - merge criterion used to get the merger from the registry, use `IMergeCriterion.NONE` if no special criterion should be set.

#### CachingDiffRelationshipComputer

    public CachingDiffRelationshipComputer(IDiffRelationshipComputer computer)

Creates a new computer by wrapping the given instance. Any computing calls are delegated to this instance and cached.

Parameters:
  `computer` - computer instance used for calculating diff relationships.

### Method Detail

#### getComputer

    protected IDiffRelationshipComputer getComputer()

Returns the internal computer instance used to compute the diff relationships.

Returns:
  internal computer instance.

#### getMergerRegistry

    public IMerger.Registry getMergerRegistry()

Description copied from interface: `IDiffRelationshipComputer`
Returns the merger registry used for calculating the diff relationships.

Specified by:
  `getMergerRegistry` in interface `IDiffRelationshipComputer`
Returns:
  The merger registry.

#### setMergerRegistry

    public void setMergerRegistry(IMerger.Registry mergerRegistry)

Sets the merger registry used for calculating the diff relationships. WARNING: Setting the merger registry invalidates previously cached results, if another registry was set previously!

Specified by:
  `setMergerRegistry` in interface `IDiffRelationshipComputer`
Parameters:
  `mergerRegistry` - The merger registry.

#### getMergeCriterion

    public IMergeCriterion getMergeCriterion()

Description copied from interface: `IDiffRelationshipComputer`
Returns the merge criterion considered for calculating the diff relationships.

Specified by:
  `getMergeCriterion` in interface `IDiffRelationshipComputer`
Returns:
  The merge criterion.

#### getMerger

    public IMerger2 getMerger(Diff diff)

Description copied from interface: `IDiffRelationshipComputer`
Returns the best-fitting merger for the given diff according to the `merger registry` and the `merge criterion`.

Specified by:
  `getMerger` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - The difference for which we seek the merger.
Returns:
  The best-fitting merger for the given diff or null if no merger fits.

#### hasMerger

    public boolean hasMerger(Diff diff)

Description copied from interface: `IDiffRelationshipComputer`
Indicates whether a best-fitting merger for the given diff is available.

Specified by:
  `hasMerger` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - The difference for which we seek the merger.
Returns:
  Returns true if a best-fitting merger is available, false otherwise.

#### setMergeCriterion

    public void setMergeCriterion(IMergeCriterion mergeCriterion)

Sets the merge criterion considered for calculating the diff relationships. WARNING: Setting the merge criterion invalidates previously cached results, if another criterion was set previously.

Specified by:
  `setMergeCriterion` in interface `IDiffRelationshipComputer`
Parameters:
  `mergeCriterion` - The merger criterion.

#### setCachedDirectMergeDependencies

    protected void setCachedDirectMergeDependencies(Diff diff,
                                                    boolean mergeRightToLeft,
                                                    Set<Diff> directMergeDependencies)

Caches the given direct merge dependencies.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
  `directMergeDependencies` - direct merge dependencies of diff

#### getCachedDirectMergeDependencies

    protected Set<Diff> getCachedDirectMergeDependencies(Diff diff,
                                                         boolean mergeRightToLeft)

Returns the cached direct merge dependencies.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct merge dependencies

#### computeDirectMergeDependencies

    protected Set<Diff> computeDirectMergeDependencies(Diff diff,
                                                       boolean mergeRightToLeft)

Computes direct merge dependencies for the given diff.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  a non-null set of direct merge dependencies

#### getDirectMergeDependencies

    public Set<Diff> getDirectMergeDependencies(Diff diff,
                                                boolean mergeRightToLeft)

Returns the cached direct merge dependencies, if present. Otherwise, the direct merge dependencies are retrieved and cached using the given merger.

Specified by:
  `getDirectMergeDependencies` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct merge dependencies
See Also:
  `IMerger2.getDirectMergeDependencies(Diff, boolean)`

#### setCachedDirectResultingMerges

    protected void setCachedDirectResultingMerges(Diff diff,
                                                  boolean mergeRightToLeft,
                                                  Set<Diff> directResultingMerges)

Caches the given direct resulting merges.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
  `directResultingMerges` - direct resulting merges

#### getCachedDirectResultingMerges

    protected Set<Diff> getCachedDirectResultingMerges(Diff diff,
                                                       boolean mergeRightToLeft)

Returns the cached direct resulting merges.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct resulting merges

#### computeDirectResultingMerges

    protected Set<Diff> computeDirectResultingMerges(Diff diff,
                                                     boolean mergeRightToLeft)

Computes direct resulting merges for the given diff.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  a non-null set of all resulting merges

#### getDirectResultingMerges

    public Set<Diff> getDirectResultingMerges(Diff diff,
                                              boolean mergeRightToLeft)

Returns the cached direct resulting merges, if present. Otherwise, the direct resulting merges are retrieved and cached using the given merger.

Specified by:
  `getDirectResultingMerges` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct resulting merges
See Also:
  `IMerger2.getDirectResultingMerges(Diff, boolean)`

#### setCachedDirectResultingRejections

    protected void setCachedDirectResultingRejections(Diff diff,
                                                      boolean mergeRightToLeft,
                                                      Set<Diff> directResultingRejections)

Caches the given direct resulting rejections.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
  `directResultingRejections` - direct resulting rejections

#### getCachedDirectResultingRejections

    protected Set<Diff> getCachedDirectResultingRejections(Diff diff,
                                                           boolean mergeRightToLeft)

Returns the cached direct resulting rejections.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct resulting rejections

#### computeDirectResultingRejections

    protected Set<Diff> computeDirectResultingRejections(Diff diff,
                                                         boolean mergeRightToLeft)

Computes the direct resulting rejections.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  a non-null set of direct resulting rejections

#### getDirectResultingRejections

    public Set<Diff> getDirectResultingRejections(Diff diff,
                                                  boolean mergeRightToLeft)

Description copied from interface: `IDiffRelationshipComputer`
Returns the set of all differences that need to be rejected if `diff` is merged in the given direction.

Specified by:
  `getDirectResultingRejections` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - The difference for which we seek the direct resulting rejections.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  A non-null set of direct resulting rejections.
See Also:
  `IDiffRelationshipComputer.getAllResultingRejections(Diff, boolean)`, `IMerger2.getDirectResultingRejections(Diff, boolean)`

#### setCachedAllResultingRejections

    protected void setCachedAllResultingRejections(Diff diff,
                                                   boolean mergeRightToLeft,
                                                   Set<Diff> allResultingRejections)

Caches the given all resulting rejections.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
  `allResultingRejections` - all resulting rejections

#### getCachedAllResultingRejections

    protected Set<Diff> getCachedAllResultingRejections(Diff diff,
                                                        boolean mergeRightToLeft)

Returns the cached all resulting rejections.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached all resulting rejections

#### computeAllResultingRejections

    protected Set<Diff> computeAllResultingRejections(Diff diff,
                                                      boolean mergeRightToLeft)

Computes all resulting rejections for the given diff.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  a non-null set of all resulting rejections

#### getAllResultingRejections

    public Set<Diff> getAllResultingRejections(Diff diff,
                                               boolean mergeRightToLeft)

Description copied from interface: `IDiffRelationshipComputer`
Retrieves the set of all diffs that will be rejected if the given `diff` is merged, either because of unresolveable conflicts or because of unreachable requirements.

Specified by:
  `getAllResultingRejections` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - The difference for which we seek all opposite ones.
  `mergeRightToLeft` - The direction in which we're considering a merge.
Returns:
  A non-null set of all diffs that will be rejected if the given `diff` is merged in the given direction.

#### setCachedAllResultingMerges

    protected void setCachedAllResultingMerges(Diff diff,
                                               boolean mergeRightToLeft,
                                               Set<Diff> allResultingMerges)

Caches the given all resulting merges.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
  `allResultingMerges` - all resulting merges

#### getCachedAllResultingMerges

    protected Set<Diff> getCachedAllResultingMerges(Diff diff,
                                                    boolean mergeRightToLeft)

Returns the cached all resulting merges.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached all resulting merges

#### computeAllResultingMerges

    protected Set<Diff> computeAllResultingMerges(Diff diff,
                                                  boolean mergeRightToLeft)

Computes all resulting merges for the given diff.

Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  a non-null set of all resulting merges

#### getAllResultingMerges

    public Set<Diff> getAllResultingMerges(Diff diff,
                                           boolean mergeRightToLeft)

Returns the cached direct resulting merges, if present. Otherwise, the direct resulting merges are retrieved and cached using the given merger.

Specified by:
  `getAllResultingMerges` in interface `IDiffRelationshipComputer`
Parameters:
  `diff` - diff
  `mergeRightToLeft` - merge direction
Returns:
  cached direct resulting merges
See Also:
  `IMerger2.getDirectResultingMerges(Diff, boolean)`

#### invalidate

    public void invalidate(Diff diff)

Invalidates the cache for the given diff, so that relationships will be re-calculated for this diff the next time a respective method is called.

Parameters:
  `diff` - diff for which the cache should be invalidated.

#### invalidate

    public void invalidate(Iterable<Diff> diffs)

Invalidates the cache for all given diffs, so that relationships will be re-calculated for each diff the next time a respective method is called.

Parameters:
  `diffs` - diffs for which the cache should be invalidated.

#### invalidate

    public void invalidate()

Invalidates the complete cache, so that relationships will be re-calculated any diff the next time a respective method is called.