Exemple #1
0
  public static <T> Diff<T> createDiff(List<T> existingElements, List<T> newElements) {
    if (existingElements == null) {
      existingElements = Collections.EMPTY_LIST;
    }
    if (newElements == null) {
      newElements = Collections.EMPTY_LIST;
    }

    Diff<T> diff = new Diff<T>();

    diff.elementsToRemove = new ArrayList<T>(existingElements);
    diff.elementsToRemove.removeAll(newElements);
    diff.elementsToAdd = new ArrayList<T>(newElements);
    diff.elementsToAdd.removeAll(existingElements);
    diff.intersectionElements = new ArrayList<T>(existingElements);
    diff.intersectionElements.removeAll(diff.elementsToRemove);

    return diff;
  }