ParseUtils { public static boolean hasIntersection(String glob1, String glob2) { if (null == glob1 || null == glob2) { return false; } if (glob1.contains("*") && glob2.contains("*")) { int index1 = glob1.indexOf("*"); int index2 = glob2.indexOf("*"); String s11 = glob1.substring(0, index1); String s12 = glob1.substring(index1 + 1, glob1.length()); String s21 = glob2.substring(0, index2); String s22 = glob2.substring(index2 + 1, glob2.length()); if(!s11.startsWith(s21) && !s21.startsWith(s11)) return false; if(!s12.endsWith(s22) && !s22.endsWith(s12)) return false; return true; } else if (glob1.contains("*")) { return isMatchGlobPattern(glob1, glob2); } else if (glob2.contains("*")) { return isMatchGlobPattern(glob2, glob1); } else { return glob1.equals(glob2); } } private  ParseUtils(); static String interpolate(String expression, Map<String, String> params); static List<String> interpolate(List<String> expressions, Map<String, String> params); static boolean isMatchGlobPattern(String pattern, String value); static boolean isMatchGlobPatternsNeedInterpolate(
            Collection<String> patternsNeedInterpolate,
            Map<String, String> interpolateParams, String value); static Set<String> filterByGlobPattern(String pattern, Collection<String> values); static Set<String> filterByGlobPattern(Collection<String> patterns, Collection<String> values); static boolean hasIntersection(String glob1, String glob2); static Map<String, String> parseQuery(String keyPrefix, String query); static Map<String, String> parseQuery(String query); static String replaceParameter(String query, String key, String value); static String appendParamToUri(String uri, String name, String value); static String appendParamsToUri(String uri, Map<String, String> params); static boolean matchEndStarPattern(String value, String pattern); static String METHOD_SPLIT; }
@Test public void test_hasIntersection() throws Exception { assertFalse(ParseUtils.hasIntersection(null, null)); assertFalse(ParseUtils.hasIntersection("dog", null)); assertFalse(ParseUtils.hasIntersection(null, "god")); assertTrue(ParseUtils.hasIntersection("hello", "hello*")); assertTrue(ParseUtils.hasIntersection("helloxxx", "hello*")); assertTrue(ParseUtils.hasIntersection("world", "*world")); assertTrue(ParseUtils.hasIntersection("xxxworld", "*world")); assertTrue(ParseUtils.hasIntersection("helloworld", "hello*world")); assertTrue(ParseUtils.hasIntersection("helloxxxworld", "hello*world")); assertFalse(ParseUtils.hasIntersection("Yhelloxxxworld", "hello*world")); assertTrue(ParseUtils.hasIntersection("hello*", "hello")); assertTrue(ParseUtils.hasIntersection("hello*", "helloxxx")); assertTrue(ParseUtils.hasIntersection("*world", "world")); assertTrue(ParseUtils.hasIntersection("*world", "xxxworld")); assertTrue(ParseUtils.hasIntersection("hello*world", "helloworld")); assertTrue(ParseUtils.hasIntersection("hello*world", "helloxxxworld")); assertFalse(ParseUtils.hasIntersection("hello*world", "Yhelloxxxworld")); assertTrue(ParseUtils.hasIntersection("*world", "hello*world")); assertTrue(ParseUtils.hasIntersection("*world", "hello*Zworld")); assertTrue(ParseUtils.hasIntersection("helloZ*", "hello*world")); assertFalse(ParseUtils.hasIntersection("Zhello*", "hello*world")); assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ")); assertTrue(ParseUtils.hasIntersection("hello*world", "hello*world")); assertTrue(ParseUtils.hasIntersection("hello*world", "hello*Zworld")); assertTrue(ParseUtils.hasIntersection("helloZ*world", "hello*world")); assertFalse(ParseUtils.hasIntersection("Zhello*world", "hello*world")); assertFalse(ParseUtils.hasIntersection("hello*world", "hello*worldZ")); }