public static String extractPartsFromURIs(List<String> uris) {
      // 1st pass on collection: find a common prefix.
      String commonURIPath = extractCommonPrefix(uris);

      // 2nd pass on collection: find a common suffix.
      String commonURIEnd = extractCommonSuffix(uris);

      // 3rd pass on collection: guess the max number of part.
      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 "";
   }
@Test
   void testExtractPartsFromURIs() {
      // Prepare a bunch of uri paths.
      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");

      // Dispatch parts in natural order.
      // Should be deduced to something like "/v2/pet/findByDate/{part1}/{part2}/{part3}"
      String dispatchCriteria = DispatchCriteriaHelper.extractPartsFromURIs(resourcePaths);
      assertEquals("part1 && part2 && part3", dispatchCriteria);

      // 2nd case: variable part is not terminating.
      resourcePaths = new ArrayList<>();
      resourcePaths.add("/v2/pet/1/tattoos");
      resourcePaths.add("/v2/pet/23/tattoos");

      // Should be deduced to something like "/v2/pet/{part1}/tattoos"
      dispatchCriteria = DispatchCriteriaHelper.extractPartsFromURIs(resourcePaths);
      assertEquals("part1", dispatchCriteria);
   }