Package org.eclipse.emf.compare.ide.ui.internal.logical

# 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 Summary

Fields
Modifier and Type
Field
Description
`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).
`static final double`
`THRESHOLD`
The maximum percentage of differing characters contained in the content for files to be considered a rename.
`static final double`
`THRESHOLD_SIZE_RATIO`
Maximum percentage of file size difference: consider that a file that is more than 10% bigger cannot be a rename of another file.

## Method Summary

Modifier and Type
Method
Description
`static double`
`computeDifference(InputStream a, InputStream b)`
Computes the difference between two `InputStream` instances.
`static boolean`
`isSimilar(InputStream a, InputStream b)`
Decides whether two input streams are similar.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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:
  - Constant Field Values

### THRESHOLD_SIZE_RATIO

public static final double THRESHOLD_SIZE_RATIO
Maximum percentage of file size difference: consider that a file that is more than 10% bigger cannot be a rename of another file.

See Also:
  - Constant Field Values

### THRESHOLD

public static final double THRESHOLD
The maximum percentage of differing characters contained in the content for files to be considered a rename.

See Also:
  - Constant Field Values

## 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