org.eclipse.jgit.diff
Class DiffAlgorithm

java.lang.Object
  extended by org.eclipse.jgit.diff.DiffAlgorithm
Direct Known Subclasses:
LowLevelDiffAlgorithm

public abstract class DiffAlgorithm
extends Object

Compares two Sequences to create an EditList of changes.

An algorithm's diff method must be callable from concurrent threads without data collisions. This permits some algorithms to use a singleton pattern, with concurrent invocations using the same singleton. Other algorithms may support parameterization, in which case the caller can create a unique instance per thread.


Nested Class Summary
static class DiffAlgorithm.SupportedAlgorithm
          Supported diff algorithm
 
Constructor Summary
DiffAlgorithm()
           
 
Method Summary
<S extends Sequence>
EditList
diff(SequenceComparator<? super S> cmp, S a, S b)
          Compare two sequences and identify a list of edits between them.
abstract
<S extends Sequence>
EditList
diffNonCommon(SequenceComparator<? super S> cmp, S a, S b)
          Compare two sequences and identify a list of edits between them.
static DiffAlgorithm getAlgorithm(DiffAlgorithm.SupportedAlgorithm alg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiffAlgorithm

public DiffAlgorithm()
Method Detail

getAlgorithm

public static DiffAlgorithm getAlgorithm(DiffAlgorithm.SupportedAlgorithm alg)
Parameters:
alg - the diff algorithm for which an implementation should be returned
Returns:
an implementation of the specified diff algorithm

diff

public <S extends Sequence> EditList diff(SequenceComparator<? super S> cmp,
                                          S a,
                                          S b)
Compare two sequences and identify a list of edits between them.

Type Parameters:
S - type of sequence being compared.
Parameters:
cmp - the comparator supplying the element equivalence function.
a - the first (also known as old or pre-image) sequence. Edits returned by this algorithm will reference indexes using the 'A' side: Edit.getBeginA(), Edit.getEndA().
b - the second (also known as new or post-image) sequence. Edits returned by this algorithm will reference indexes using the 'B' side: Edit.getBeginB(), Edit.getEndB().
Returns:
a modifiable edit list comparing the two sequences. If empty, the sequences are identical according to cmp's rules. The result list is never null.

diffNonCommon

public abstract <S extends Sequence> EditList diffNonCommon(SequenceComparator<? super S> cmp,
                                                            S a,
                                                            S b)
Compare two sequences and identify a list of edits between them. This method should be invoked only after the two sequences have been proven to have no common starting or ending elements. The expected elimination of common starting and ending elements is automatically performed by the diff(SequenceComparator, Sequence, Sequence) method, which invokes this method using Subsequences.

Type Parameters:
S - type of sequence being compared.
Parameters:
cmp - the comparator supplying the element equivalence function.
a - the first (also known as old or pre-image) sequence. Edits returned by this algorithm will reference indexes using the 'A' side: Edit.getBeginA(), Edit.getEndA().
b - the second (also known as new or post-image) sequence. Edits returned by this algorithm will reference indexes using the 'B' side: Edit.getBeginB(), Edit.getEndB().
Returns:
a modifiable edit list comparing the two sequences.


Copyright © 2013. All Rights Reserved.