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

com.developerdan.blocklist.tools.ListDiff Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.developerdan.blocklist.tools;

import java.util.NavigableSet;
import java.util.TreeSet;

public class ListDiff {
    public static String DomainList(final NavigableSet before, final NavigableSet after) {
        var patchBuilder = new PatchBuilder();
        TreeSet removedDomains = ListDiff.difference(before, after);
        TreeSet addedDomains = ListDiff.difference(after, before);
        TreeSet allDomains = new TreeSet<>(before);
        allDomains.addAll(after);
        for(Domain entry : allDomains) {
            if (removedDomains.contains(entry)) {
                patchBuilder.removed(entry);
            } else if (addedDomains.contains(entry)) {
                patchBuilder.added(entry);
            } else {
                patchBuilder.noChange(entry);
            }
        }
        return patchBuilder.toString();
    }

    private static TreeSet difference(final NavigableSet before, final NavigableSet after) {
        TreeSet removedDomains = new TreeSet<>(before);
        removedDomains.removeAll(after);
        return removedDomains;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy