DispatchCriteriaHelper { public static String extractPartsFromURIs(List<String> uris){ String commonURIPath = extractCommonPrefix(uris); String commonURIEnd = extractCommonSuffix(uris); int partsLen = 0; for (String uri : uris) { String parts = uri.substring(commonURIPath.length() + 1); if (commonURIEnd != null) { parts = parts.substring(0, parts.lastIndexOf(commonURIEnd)); } int numOfParts = parts.split("/").length; if (numOfParts > partsLen) { partsLen = numOfParts; } } if (partsLen > 0) { StringBuilder parts = new StringBuilder(); for (int i = 0; i < partsLen; i++) { parts.append("part").append(i + 1); if (i < partsLen - 1) { parts.append(" && "); } } return parts.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 testExtractPartsFromURIs(){ List<String> resourcePaths = new ArrayList<>(); resourcePaths.add("/v2/pet/findByDate/2017"); resourcePaths.add("/v2/pet/findByDate/2016/12"); resourcePaths.add("/v2/pet/findByDate/2016/12/20"); String dispatchCriteria = DispatchCriteriaHelper.extractPartsFromURIs(resourcePaths); assertEquals("part1 && part2 && part3", dispatchCriteria); resourcePaths = new ArrayList<>(); resourcePaths.add("/v2/pet/1/tattoos"); resourcePaths.add("/v2/pet/23/tattoos"); dispatchCriteria = DispatchCriteriaHelper.extractPartsFromURIs(resourcePaths); assertEquals("part1", dispatchCriteria); }