Class CachingDiffRelationshipComputer

java.lang.Object
org.eclipse.emf.compare.merge.DiffRelationshipComputer
org.eclipse.emf.compare.merge.CachingDiffRelationshipComputer
All Implemented Interfaces:
IDiffRelationshipComputer

public class CachingDiffRelationshipComputer extends DiffRelationshipComputer
A computer implementation to cache the relationship of diffs. Note that the "all" relationships are not cached because they would O(n^2) memory in the general case.
Since:
3.5
See Also:
  • Field Details

    • 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.
  • Constructor Details

    • 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.
  • Method Details

    • 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
      Overrides:
      setMergerRegistry in class DiffRelationshipComputer
      Parameters:
      mergerRegistry - The merger registry.
    • 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
      Overrides:
      setMergeCriterion in class DiffRelationshipComputer
      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
      Overrides:
      getDirectMergeDependencies in class DiffRelationshipComputer
      Parameters:
      diff - diff
      mergeRightToLeft - merge direction
      Returns:
      cached direct merge dependencies
      See Also:
    • 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
      Overrides:
      getDirectResultingMerges in class DiffRelationshipComputer
      Parameters:
      diff - diff
      mergeRightToLeft - merge direction
      Returns:
      cached direct resulting merges
      See Also:
    • 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
      Overrides:
      getDirectResultingRejections in class DiffRelationshipComputer
      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:
    • computeCache

      public void computeCache(Diff diff)
      Computes the cached relationships for the give diff.
      Parameters:
      diff - the diff for which to cmpute the cached relationship.
    • 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.