DispatchCriteriaHelper { public static String buildFromParamsMap(String paramsRule, Map<String, String> paramsMap) { if (paramsMap != null && !paramsMap.isEmpty()) { Map<String, String> criteriaMap = new TreeMap<String, String>(); criteriaMap.putAll(paramsMap); StringBuilder result = new StringBuilder(); for (String criteria : criteriaMap.keySet()) { if (paramsRule.contains(criteria)) { result.append("?").append(criteria).append("=").append(criteriaMap.get(criteria)); } } return result.toString(); } return ""; }  static String extractParamsFromURI(String uri); static String extractCommonPrefix(List<String> uris); static String extractCommonSuffix(List<String> uris); static String extractPartsFromURIs(List<String> uris); static String extractPartsFromURIPattern(String pattern); static String extractFromURIPattern(String pattern, String realURI); static String buildFromPartsMap(Map<String, String> partsMap); static String buildFromParamsMap(String paramsRule, Map<String, String> paramsMap); static String extractFromURIParams(String paramsRule, String uri);  }
@Test public void testBuildFromParamsMap() { Map<String, String> paramsMap = new HashMap<>(); paramsMap.put("page", "1"); paramsMap.put("limit", "20"); paramsMap.put("status", "available"); String dispatchCriteria = DispatchCriteriaHelper.buildFromParamsMap("page", paramsMap); assertEquals("?page=1", dispatchCriteria); dispatchCriteria = DispatchCriteriaHelper.buildFromParamsMap("page && limit", paramsMap); assertEquals("?limit=20?page=1", dispatchCriteria); }