@Test public void test_isMatchCondition()throws Exception { Map<String, RouteRule.MatchPair> condition = new HashMap<String, RouteRule.MatchPair>(); Map<String, String> valueParams = new HashMap<String, String>(); Map<String, String> kv = new HashMap<String, String>(); boolean output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertTrue(output); { Set<String> matches = new HashSet<String>(); matches.add("value1_1"); matches.add("value1_2"); matches.add("value1_3"); Set<String> unmatches = new HashSet<String>(); unmatches.add("v1_1"); unmatches.add("v1_2"); unmatches.add("v1_3"); RouteRule.MatchPair p = new RouteRule.MatchPair(matches, unmatches); condition.put("key1", p); matches = new HashSet<String>(); matches.add("value2_1"); matches.add("value2_2"); matches.add("value2_3"); unmatches = new HashSet<String>(); unmatches.add("v2_1"); unmatches.add("v2_2"); unmatches.add("v2_3"); p = new RouteRule.MatchPair(matches, unmatches); condition.put("key2", p); } kv.put("kkk", "vvv"); output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertFalse(output); kv.put("key1", "vvvXXX"); output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertFalse(output); kv.put("key1", "value1_1"); output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertFalse(output); kv.put("key2", "value2_1"); output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertTrue(output); kv.put("key1", "v1_2"); output = RouteRuleUtils.isMatchCondition(condition, valueParams, kv); assertFalse(output); }
public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && ! ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; }
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && ! ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } }
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && ! ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private  RouteRuleUtils(); }
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && ! ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private  RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
            Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
            Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
            Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule); }
RouteRuleUtils { public static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition, Map<String, String> valueParams, Map<String, String> kv) { if (condition != null && condition.size() > 0) { for (Map.Entry<String, RouteRule.MatchPair> entry : condition.entrySet()) { String condName = entry.getKey(); RouteRule.MatchPair p = entry.getValue(); String value = kv.get(condName); Set<String> matches = p.getMatches(); if (matches != null && matches.size() > 0 && ! ParseUtils.isMatchGlobPatternsNeedInterpolate(matches, valueParams, value)) { return false; } Set<String> unmatches = p.getUnmatches(); if (unmatches != null && unmatches.size() > 0 && ParseUtils.isMatchGlobPatternsNeedInterpolate(unmatches, valueParams, value)) { return false; } } } return true; } private  RouteRuleUtils(); static Map<String, RouteRule.MatchPair> expandCondition(
            Map<String, RouteRule.MatchPair> condition, String srcKeyName, String destKeyName,
            Map<String, T> expandName2Set); static boolean isMatchCondition(Map<String, RouteRule.MatchPair> condition,
            Map<String, String> valueParams, Map<String, String> kv); static Set<String> filterServiceByRule(List<String> services, RouteRule rule);  }