All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.incava.diff.Diff Maven / Gradle / Ivy

There is a newer version: 1.1.2
Show newest version
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