Class Diff<Type>

java.lang.Object
org.jjazz.utilities.api.Diff<Type>
Type Parameters:
Type -

public class Diff<Type> extends Object
Compares two lists, 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") list 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" lists; otherwise, for speed, hash codes from the objects will be used instead for comparison.

JJazzLab changes: updated so that each CHANGED difference has the same number of objects in/out.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Represents a difference.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> List<Diff.Difference>
    diff(List<T> a, List<T> b)
    Compute differences for the two lists, using the default comparison mechanism between the objects, such as equals and compareTo.
    static <T> List<Diff.Difference>
    diff(List<T> a, List<T> b, Comparator<T> comp)
    Compute differences for the two lists, using the specified comparison mechanism.
    static <T> List<Diff.Difference>
    diff(T[] a, T[] b)
    Compute differences for the two arrays, using the default comparison mechanism between the objects, such as equals and compareTo.
    static <T> List<Diff.Difference>
    diff(T[] a, T[] b, Comparator<T> comp)
    Compute differences for the two arrays, using the specified comparison mechanism.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • diff

      public static <T> List<Diff.Difference> diff(T[] a, T[] b, Comparator<T> comp)
      Compute differences for the two arrays, using the specified comparison mechanism.
      Type Parameters:
      T -
      Parameters:
      a -
      b -
      comp -
      Returns:
    • diff

      public static <T> List<Diff.Difference> diff(T[] a, T[] b)
      Compute differences for the two arrays, using the default comparison mechanism between the objects, such as equals and compareTo.
      Type Parameters:
      T -
      Parameters:
      a -
      b -
      Returns:
    • diff

      public static <T> List<Diff.Difference> diff(List<T> a, List<T> b, Comparator<T> comp)
      Compute differences for the two lists, using the specified comparison mechanism.
      Type Parameters:
      T -
      Parameters:
      a -
      b -
      comp -
      Returns:
    • diff

      public static <T> List<Diff.Difference> diff(List<T> a, List<T> b)
      Compute differences for the two lists, using the default comparison mechanism between the objects, such as equals and compareTo.
      Type Parameters:
      T -
      Parameters:
      a -
      b -
      Returns: