class NetUtils {

    public static boolean inetAddressConflict(InetAddress testAddress, InetAddress filterAddress, InetAddress testMask,
            InetAddress filterMask) {
        // Sanity check
        if (testAddress == null || filterAddress == null) {
            return false;
        }

        // Presence check
        if (isAny(testAddress) || isAny(filterAddress)) {
            return false;
        }

        int testMaskLen = testMask == null ? testAddress instanceof Inet4Address ? 32 : 128
                : NetUtils.getSubnetMaskLength(testMask);
        int filterMaskLen = filterMask == null ? testAddress instanceof Inet4Address ? 32 : 128
                : NetUtils.getSubnetMaskLength(filterMask);

        // Mask length check. Test mask has to be more specific than filter one
        if (testMaskLen < filterMaskLen) {
            return true;
        }

        // Subnet Prefix on filter mask length must be the same
        InetAddress prefix1 = getSubnetPrefix(testAddress, filterMaskLen);
        InetAddress prefix2 = getSubnetPrefix(filterAddress, filterMaskLen);
        return !prefix1.equals(prefix2);
    }

    private  NetUtils();

}