![JAR search and dependency download from the Maven repository](/logo.png)
org.incava.diff.Diff Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-diff Show documentation
Show all versions of java-diff Show documentation
Longest common subsequences implementation
package org.incava.diff;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
/**
* Compares two collections, returning a list of the additions, changes, and
* deletions between them. A Comparator
may be passed as an
* argument to the constructor, and will thus be used. If not provided, the
* initial value in the a
("from") collection will be looked at to
* see if it supports the Comparable
interface. If so, its
* equals
and compareTo
methods will be invoked on the
* instances in the "from" and "to" collections; otherwise, for speed, hash
* codes from the objects will be used instead for comparison.
*
* The file FileDiff.java shows an example usage of this class, in an
* application similar to the Unix "diff" program.
*/
public class Diff extends Differ {
/**
* Constructs the Diff object for the two arrays, using the given comparator.
*/
public Diff(T[] a, T[] b, Comparator comp) {
this(Arrays.asList(a), Arrays.asList(b), comp);
}
/**
* Constructs the Diff object for the two arrays, using the default
* comparison mechanism between the objects, such as equals
and
* compareTo
.
*/
public Diff(T[] a, T[] b) {
this(a, b, null);
}
/**
* Constructs the Diff object for the two collections, using the default
* comparison mechanism between the objects, such as equals
and
* compareTo
.
*/
public Diff(List a, List b) {
this(a, b, null);
}
/**
* Constructs the Diff object for the two collections, using the given
* comparator.
*/
public Diff(List a, List b, Comparator comp) {
super(a, b, comp);
}
/**
* Returns a legacy Difference
See Differ
to
* return a subclass of Difference.
*/
public Difference createDifference(Integer delStart, Integer delEnd, Integer addStart, Integer addEnd) {
return new Difference(delStart, delEnd, addStart, addEnd);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy