code: private int getSubstitutionIndex(String param, String path) {
          final String match = String.format("{%s}", param);
  
          if (path.startsWith("/")) {
              path = path.substring(1);
          }
          if (path.endsWith("/")) {
              path = path.substring(0, path.length()-1);
          }
  
          String[] segments = path.split("/");
          for (int i=0; i < segments.length; i++) {
              if (match.equals(segments[i])) {
                  return i;
              }
          }
  
          return -segments.length;
      }
docs: Gets the index in a path where the substitution parameter was found, or the negative of the number of segments
  in the path if it was not found.  For example:
  
  assert(getSubstitutionIndex("id", "resource/{id}/move") == 1)
  assert(getSubstitutionIndex("not_found", "path/with/four/segments") == -4)