static Map<String, MatchPair> parseNameAndValueListString2Condition( Map<String, String> params, Map<String, String> notParams) { Map<String, MatchPair> condition = new HashMap<String, RouteRule.MatchPair>(); for (Entry<String, String> entry : params.entrySet()) { String valueListString = entry.getValue(); if (StringUtils.isBlank(valueListString)) { continue; } String[] list = VALUE_LIST_SEPARATOR.split(valueListString); Set<String> set = new HashSet<String>(); for (String item : list) { if (StringUtils.isBlank(item)) { continue; } set.add(item.trim()); } if (set.isEmpty()) { continue; } String key = entry.getKey(); MatchPair matchPair = condition.get(key); if (null == matchPair) { matchPair = new MatchPair(); condition.put(key, matchPair); } matchPair.matches = set; } for (Entry<String, String> entry : notParams.entrySet()) { String valueListString = entry.getValue(); if (StringUtils.isBlank(valueListString)) { continue; } String[] list = VALUE_LIST_SEPARATOR.split(valueListString); Set<String> set = new HashSet<String>(); for (String item : list) { if (StringUtils.isBlank(item)) { continue; } set.add(item.trim()); } if (set.isEmpty()) { continue; } String key = entry.getKey(); MatchPair matchPair = condition.get(key); if (null == matchPair) { matchPair = new MatchPair(); condition.put(key, matchPair); } matchPair.unmatches = set; } return condition; }
public boolean isThenContainValue(String key, String value) { MatchPair matchPair = thenCondition.get(key); if (null == matchPair) { return false; } return matchPair.containeValue(value); }
/** * 样本是否通过条件。 * * <p>如果样本的KV中,存在Key有对应的MatchPair,且Value不通过MatchPair里,返回{@code false}; 否则返回{@code true}。 * * @see MatchPair#pass(String) */ public static boolean matchCondition( Map<String, String> sample, Map<String, MatchPair> condition) { for (Map.Entry<String, String> entry : sample.entrySet()) { String key = entry.getKey(); MatchPair pair = condition.get(key); if (pair != null && !pair.pass(entry.getValue())) { return false; } } return true; }