package ru.kirillius.pf.sdn.Util;

import java.util.ArrayList;
import java.util.List;

/**
 * Helper methods for IPv4 address manipulation and subnet aggregation logic.
 */
public class DomainUtil {

    private DomainUtil() {
    }

    //TODO test
    public static List<String> removeOverlapped(List<String> source) {
        var result = new ArrayList<>(source);
        if (source.size() < 2) {
            return result;
        }

        //check subnets overlaps
        var overlapped = new ArrayList<String>();
        source.forEach(domain -> {
            var pattern = "." + domain;
            source.forEach(candidate -> {
                if (candidate.endsWith(pattern)) {
                    overlapped.add(candidate);
                }
            });
        });

        result.removeAll(overlapped);
        return result;
    }

}
