mirror of https://github.com/micromata/borgbackup-butler.git

Kai Reinhard
28.10.2018 34de8e3ff4872c7e48e78d1fa102aa029ac2b261
borgbutler-core/src/main/java/de/micromata/borgbutler/DiffTool.java
@@ -1,6 +1,6 @@
package de.micromata.borgbutler;
import de.micromata.borgbutler.json.borg.BorgFilesystemItem;
import de.micromata.borgbutler.cache.FilesystemItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -19,14 +19,14 @@
     * @param otherItems Sorted list of items of the archive to extract differences.
     * @return A list of differing items (new, removed and modified ones).
     */
    public static List<BorgFilesystemItem> extractDifferences(List<BorgFilesystemItem> items, List<BorgFilesystemItem> otherItems) {
        List<BorgFilesystemItem> currentList = items != null ? items : new ArrayList<>();
        List<BorgFilesystemItem> otherList = otherItems != null ? otherItems : new ArrayList<>();
        List<BorgFilesystemItem> result = new ArrayList<>();
        Iterator<BorgFilesystemItem> currentIt = currentList.iterator();
        Iterator<BorgFilesystemItem> otherIt = otherList.iterator();
        BorgFilesystemItem current = null;
        BorgFilesystemItem other = null;
    public static List<FilesystemItem> extractDifferences(List<FilesystemItem> items, List<FilesystemItem> otherItems) {
        List<FilesystemItem> currentList = items != null ? items : new ArrayList<>();
        List<FilesystemItem> otherList = otherItems != null ? otherItems : new ArrayList<>();
        List<FilesystemItem> result = new ArrayList<>();
        Iterator<FilesystemItem> currentIt = currentList.iterator();
        Iterator<FilesystemItem> otherIt = otherList.iterator();
        FilesystemItem current = null;
        FilesystemItem other = null;
        while (true) {
            if (current == null && currentIt.hasNext())
                current = currentIt.next();
@@ -42,25 +42,25 @@
                    continue;
                }
                // Current entry differs:
                current.setDiffStatus(BorgFilesystemItem.DiffStatus.MODIFIED);
                current.setDiffStatus(FilesystemItem.DiffStatus.MODIFIED);
                current.setDiffItem(other);
                current.buildDifferencesString();
                result.add(current);
                current = other = null; // increment both iterators.
            } else if (cmp < 0) {
                result.add(current.setDiffStatus(BorgFilesystemItem.DiffStatus.NEW));
                result.add(current.setDiffStatus(FilesystemItem.DiffStatus.NEW));
                current = currentIt.hasNext() ? currentIt.next() : null;
            } else {
                result.add(other.setDiffStatus(BorgFilesystemItem.DiffStatus.REMOVED));
                result.add(other.setDiffStatus(FilesystemItem.DiffStatus.REMOVED));
                other = otherIt.hasNext() ? otherIt.next() : null;
            }
        }
        while (current != null) {
            result.add(current.setDiffStatus(BorgFilesystemItem.DiffStatus.NEW));
            result.add(current.setDiffStatus(FilesystemItem.DiffStatus.NEW));
            current = currentIt.hasNext() ? currentIt.next() : null;
        }
        while (other != null) {
            result.add(other.setDiffStatus(BorgFilesystemItem.DiffStatus.REMOVED));
            result.add(other.setDiffStatus(FilesystemItem.DiffStatus.REMOVED));
            other = otherIt.hasNext() ? otherIt.next() : null;
        }
        return result;