Class SimilarityComputer

java.lang.Object
org.eclipse.emf.compare.ide.ui.internal.logical.SimilarityComputer

public final class SimilarityComputer extends Object
This class is responsible for computing similarities between two text contents and deciding whether they are close enough to be considered a rename.
  • Field Details

    • MINIMUM_LENGTH

      public static final int MINIMUM_LENGTH
      The minimum length both sides must have to not be ignored (short text contents might seem similar and cause false negatives).
      See Also:
    • THRESHOLD

      public static final double THRESHOLD
      The maximum percentage of differing lines contained in the content for files to be considered a rename.
      See Also:
  • Method Details

    • isSimilar

      public static boolean isSimilar(InputStream a, InputStream b) throws IOException
      Decides whether two input streams are similar. This methods calls computeDifference(InputStream, InputStream) and compares the value with THRESHOLD.
      Parameters:
      a - the first input stream
      b - the second input stream
      Returns:
      true if the input streams are similar
      Throws:
      IOException - if reading of one of the input streams fails
    • computeDifference

      public static double computeDifference(InputStream a, InputStream b) throws IOException
      Computes the difference between two InputStream instances. The returned value is a ratio of changed lines to total lines, where total lines is denoted by the maximum of the line counts of both input streams. This method returns Double.MAX_VALUE if one or both of the streams are null or if the content is too short to be compared (shorter than MINIMUM_LENGTH).
      Parameters:
      a - the first input stream
      b - the second input stream
      Returns:
      how different the two streams are
      Throws:
      IOException - if reading of one of the input streams fails