public static boolean matchDomain(String name, String pattern) {
        final int index = pattern.indexOf('*');
        if (index == -1) {
            return name.equals(pattern);
        } else {
            String[] names = name.split("\\.");
            String[] patterns = pattern.split("\\.");
            if (patterns.length > names.length) {
                return false;
            }
            int nameIndexDiff = names.length - patterns.length;
            for (int i = patterns.length - 1; i > -1; i--) {
                if ("*".equals(patterns[i])) {
                    continue;
                }
                if (!patterns[i].equals(names[i + nameIndexDiff])) {
                    return false;
                }
            }
            return true;
        }
    }
@Test
    public void testMatchDomain() {
        assertTrue(AddressUtil.matchDomain("hazelcast.com", "hazelcast.com"));
        assertTrue(AddressUtil.matchDomain("hazelcast.com", "*.com"));
        assertTrue(AddressUtil.matchDomain("jobs.hazelcast.com", "*.hazelcast.com"));
        assertTrue(AddressUtil.matchDomain("download.hazelcast.org", "*.hazelcast.*"));
        assertTrue(AddressUtil.matchDomain("download.hazelcast.org", "*.hazelcast.org"));

        assertFalse(AddressUtil.matchDomain("hazelcast.com", "abc.com"));
        assertFalse(AddressUtil.matchDomain("hazelcast.com", "*.hazelcast.com"));
        assertFalse(AddressUtil.matchDomain("hazelcast.com", "hazelcast.com.tr"));
        assertFalse(AddressUtil.matchDomain("hazelcast.com", "*.com.tr"));
        assertFalse(AddressUtil.matchDomain("www.hazelcast.com", "www.hazelcast.com.tr"));
    }