Class DiffUtils


  • public class DiffUtils
    extends Object
    Calculate diffs between strings and other methods to manipulate the differences.
    Version:
    $Id: DiffUtils.java 11676 2008-06-27 14:59:26Z baranda $
    Author:
    Bruno Aranda (baranda@ebi.ac.uk)
    • Method Detail

      • diff

        public static List<Diff> diff​(String str1,
                                      String str2)
        Checks the differences between two strings.
        Parameters:
        str1 - String 1
        str2 - String 2
        Returns:
        A list of Diff objects with the differences
      • filterDiffsByOperation

        public static List<Diff> filterDiffsByOperation​(List<Diff> diffs,
                                                        Operation operation)
        Filters, creating a copy, a list of Diffs by operation.
        Parameters:
        diffs - The list to filter
        operation - The operation to look for
        Returns:
        The filtered list
      • calculateIndexShift

        public static int calculateIndexShift​(List<Diff> diffs,
                                              int originalIndex)
        Taking into account the differences, calculates what the index should be in the second string by providing an index for the first string. The algorithm used: if the originalIndex is contained by any of the deleted regions in the string 1, then -1 is returned (that bit was deleted). If not, the shifted index will be the difference between amount of insertions and amount of deletions before and including the original index.
        Parameters:
        diffs - Differences for string1 and string2
        originalIndex - The index in string1
        Returns:
        The index in string2, corresponding to the index in string1 computing the differences