Class DiffUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic double
diceCoefficient
(String first, String second) Deprecated.Computes the dice coefficient between the two given String's bigrams.static <E> int
findInsertionIndex
(Comparison comparison, Iterable<E> ignoredElements, List<E> source, List<E> target, E newElement) Deprecated.This will try and determine the index at which a given element from thesource
list should be inserted in thetarget
list.static <E> int
findInsertionIndex
(Comparison comparison, List<E> source, List<E> target, E newElement) Deprecated.This will try and determine the index at which a given element from thesource
list should be inserted in thetarget
list.static int
findInsertionIndex
(Comparison comparison, Diff diff, boolean rightToLeft) Deprecated.This is the main entry point for#findInsertionIndex(Comparison, EqualityHelper, Iterable, List, List, Object)
.getAssociatedDiffs
(Diff diffRoot, Iterable<Diff> subDiffs, boolean leftToRight) Deprecated.getSubDiffs
(boolean leftToRight) Deprecated.When merging aDiff
, returns the sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)
) of these sub diffs.static <E> List<E>
longestCommonSubsequence
(Comparison comparison, Iterable<E> ignoredElements, List<E> sequence1, List<E> sequence2) Deprecated.This will compute the longest common subsequence between the two given Lists, ignoring any object that is included inignoredElements
.static <E> List<E>
longestCommonSubsequence
(Comparison comparison, List<E> sequence1, List<E> sequence2) Deprecated.This will compute the longest common subsequence between the two given Lists.
-
Method Details
-
diceCoefficient
Deprecated.Computes the dice coefficient between the two given String's bigrams.This implementation is case sensitive.
- Parameters:
first
- First of the two Strings to compare.second
- Second of the two Strings to compare.- Returns:
- The dice coefficient of the two given String's bigrams, ranging from 0 to 1.
-
longestCommonSubsequence
public static <E> List<E> longestCommonSubsequence(Comparison comparison, Iterable<E> ignoredElements, List<E> sequence1, List<E> sequence2) Deprecated.This will compute the longest common subsequence between the two given Lists, ignoring any object that is included inignoredElements
. We will useEqualityHelper.matchingValues(Comparison, Object, Object)
in order to try and match the values from both lists two-by-two. This can thus be used both for reference values or attribute values. If there are two subsequences of the same "longest" length, the first (according to the second argument) will be returned.Take note that this might be slower than
#longestCommonSubsequence(Comparison, EqualityHelper, List, List)
and should only be used when elements should be removed from the potential LCS. This is mainly aimed at merge operations during three-way comparisons as some objects might be in conflict and thus shifting the computed insertion indices.Please see
#longestCommonSubsequence(Comparison, EqualityHelper, List, List)
for a more complete description.- Type Parameters:
E
- Type of the sequences content.- Parameters:
comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.ignoredElements
- Specifies elements that should be excluded from the subsequences.sequence1
- First of the two sequences to consider.sequence2
- Second of the two sequences to consider.- Returns:
- The LCS of the two given sequences. Will never be the same instance as one of the input sequences.
-
longestCommonSubsequence
public static <E> List<E> longestCommonSubsequence(Comparison comparison, List<E> sequence1, List<E> sequence2) Deprecated.This will compute the longest common subsequence between the two given Lists. We will useEqualityHelper.matchingValues(Comparison, Object, Object)
in order to try and match the values from both lists two-by-two. This can thus be used both for reference values or attribute values. If there are two subsequences of the same "longest" length, the first (according to the second argument) will be returned.For example, it the two given sequence are, in this order,
{"a", "b", "c", "d", "e"}
and{"c", "z", "d", "a", "b"}
, there are two "longest" subsequences :{"a", "b"}
and{"c", "d"}
. The first of those two subsequences in the second list is{"c", "d"}
. On the other hand, the LCS of{"a", "b", "c", "d", "e"}
and{"y", "c", "d", "e", "b"}
is{"c", "d", "e"}
.The following algorithm has been inferred from the wikipedia article on the Longest Common Subsequence, http://en.wikipedia.org/wiki/Longest_common_subsequence_problem at the time of writing. It is decomposed in two : we first compute the LCS matrix, then we backtrack through the input to determine the LCS. Evaluation will be shortcut after the first part if the LCS is one of the two input sequences.
Note : we are not using Iterables as input in order to make use of the random access cost of ArrayLists. This might also be converted to directly use arrays. This implementation will not play well with LinkedLists or any List which needs to iterate over the values for each call to
List.get(int)
, i.e any list which is not instanceof RandomAccess or does not satisfy its contract.- Type Parameters:
E
- Type of the sequences content.- Parameters:
comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.sequence1
- First of the two sequences to consider.sequence2
- Second of the two sequences to consider.- Returns:
- The LCS of the two given sequences. Will never be the same instance as one of the input sequences.
-
findInsertionIndex
public static <E> int findInsertionIndex(Comparison comparison, Iterable<E> ignoredElements, List<E> source, List<E> target, E newElement) Deprecated.This will try and determine the index at which a given element from thesource
list should be inserted in thetarget
list. We expectnewElement
to be an element from thesource
or to have a Match that allows us to map it to one of thesource
list's elements.The expected insertion index will always be relative to the Longest Common Subsequence (LCS) between the two given lists, ignoring all elements from that LCS that have changed between the target list and the common origin of the two. If there are more than one "longest" subsequence between the two lists, the insertion index will be relative to the first that comes in the
target
list.Note : we are not using Iterables as input in order to make use of the random access cost of ArrayLists. This might also be converted to directly use arrays. This implementation will not play well with LinkedLists or any List which needs to iterate over the values for each call to
List.get(int)
, i.e any list which is not instanceof RandomAccess or does not satisfy its contract.- Type Parameters:
E
- Type of the sequences content.- Parameters:
comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.ignoredElements
- If there are elements fromtarget
that should be ignored when searching for an insertion index, set them here. Can benull
or an empty list.source
- The List from which one element has to be added to thetarget
list.target
- The List into which one element fromsource
has to be added.newElement
- The element fromsource
that needs to be added intotarget
.- Returns:
- The index at which
newElement
should be inserted intarget
. - See Also:
- Restriction:
- This method is not intended to be referenced by clients.
-
findInsertionIndex
public static <E> int findInsertionIndex(Comparison comparison, List<E> source, List<E> target, E newElement) Deprecated.This will try and determine the index at which a given element from thesource
list should be inserted in thetarget
list. We expectnewElement
to be an element from thesource
or to have a Match that allows us to map it to one of thesource
list's elements.The expected insertion index will always be relative to the Longest Common Subsequence (LCS) between the two given lists. If there are more than one "longest" subsequence between the two lists, the insertion index will be relative to the first that comes in the
target
list.For example, assume
source
is{"1", "2", "4", "6", "8", "3", "0", "7", "5"}
andtarget
is{"8", "1", "2", "9", "3", "4", "7"}
; I try to merge the addition of"0"
in the right list. The returned "insertion index" will be5
: just after"3"
. There are two subsequence of the same "longest" length 4 :{"1", "2", "3", "7"}
and{"1", "2", "4", "7"}
. However, the first of those two intarget
is{"1", "2", "3", "7"}
. The closest element before"0"
in this LCS insource
is"3"
.Note : we are not using Iterables as input in order to make use of the random access cost of ArrayLists. This might also be converted to directly use arrays. This implementation will not play well with LinkedLists or any List which needs to iterate over the values for each call to
List.get(int)
, i.e any list which is not instanceof RandomAccess or does not satisfy its contract.- Type Parameters:
E
- Type of the sequences content.- Parameters:
comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.source
- The List from which one element has to be added to thetarget
list.target
- The List into which one element fromsource
has to be added.newElement
- The element fromsource
that needs to be added intotarget
.- Returns:
- The index at which
newElement
should be inserted intarget
. - See Also:
-
findInsertionIndex
Deprecated.This is the main entry point for#findInsertionIndex(Comparison, EqualityHelper, Iterable, List, List, Object)
. It will use default algorithms to determine the source and target lists as well as the list of elements that should be ignored when computing the insertion index.- Parameters:
comparison
- This will be used in order to retrieve the Match for EObjects when comparing them.diff
- The diff which merging will trigger the need for an insertion index in its target list.rightToLeft
-true
if the merging will be done into the left list, so that we should consider the right model as the source and the left as the target.- Returns:
- The index at which this
diff
's value should be inserted into the 'target' list, as inferred fromrightToLeft
. - See Also:
-
getSubDiffs
Deprecated.When merging aDiff
, returns the sub diffs of this given diff, and all associated diffs (seeDiffUtil#getAssociatedDiffs(Iterable, boolean, Diff)
) of these sub diffs.If the diff is an
AttributeChange
, aFeatureMapChange
or a @{code ResourceAttachmentChange}, this method will return an empty iterable.If the diff is a
ReferenceChange
this method will return all differences contained in the match that contains the value of the reference change, and all associated diffs of these differences.- Parameters:
leftToRight
- the direction of merge.- Returns:
- an iterable containing the sub diffs of this given diff, and all associated diffs of these sub diffs.
- Since:
- 3.0
-
getAssociatedDiffs
@Deprecated public static Iterable<Diff> getAssociatedDiffs(Diff diffRoot, Iterable<Diff> subDiffs, boolean leftToRight) Deprecated.When merging aDiff
, returns the associated diffs of the sub diffs of the diff, and all sub diffs (seegetSubDiffs(boolean)
) of these associated diffs.The associated diffs of a diff are :
-
Diff.getRequiredBy()
if the source of the diff is the left side and the direction of the merge is right to left.-
Diff.getRequiredBy()
if the source of the diff is the right side and the direction of the merge is left to right.-
Diff.getRequires()
if the source of the diff is the left side and the direction of the merge is left to right.-
Diff.getRequires()
if the source of the diff is the right side and the direction of the merge is right to left.- Parameters:
diffRoot
- the given diff.subDiffs
- the iterable of sub diffs for which we want the associated diffs.leftToRight
- the direction of merge.- Returns:
- an empty list.
- Since:
- 3.0
-