/**
  * Compares "this" info (i.e. the current instance) with another info in the context of a request.
  *
  * <p>Note: it is assumed both instances have been obtained via {@link
  * #getMatchingInfo(HttpServletRequest)} to ensure they have conditions with content relevant to
  * current request.
  */
 public int compareTo(RequestMappingInfo other, HttpServletRequest request) {
   int result = patternsCondition.compareTo(other.getPatternsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = paramsCondition.compareTo(other.getParamsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = headersCondition.compareTo(other.getHeadersCondition(), request);
   if (result != 0) {
     return result;
   }
   result = consumesCondition.compareTo(other.getConsumesCondition(), request);
   if (result != 0) {
     return result;
   }
   result = producesCondition.compareTo(other.getProducesCondition(), request);
   if (result != 0) {
     return result;
   }
   result = methodsCondition.compareTo(other.getMethodsCondition(), request);
   if (result != 0) {
     return result;
   }
   result = customCondition.compareTo(other.customCondition, request);
   if (result != 0) {
     return result;
   }
   return 0;
 }
 private RequestMappingInfo withNewPatterns(RequestMappingInfo mapping, String[] patternStrings) {
   PatternsRequestCondition patterns =
       new PatternsRequestCondition(
           patternStrings, null, null, useSuffixPatternMatch(), useTrailingSlashMatch(), null);
   return new RequestMappingInfo(
       patterns,
       mapping.getMethodsCondition(),
       mapping.getParamsCondition(),
       mapping.getHeadersCondition(),
       mapping.getConsumesCondition(),
       mapping.getProducesCondition(),
       mapping.getCustomCondition());
 }
  @Override
  protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {

    RequestMappingInfo defaultMapping = super.getMappingForMethod(method, handlerType);
    if (defaultMapping == null) {
      return null;
    }

    Set<String> defaultPatterns = defaultMapping.getPatternsCondition().getPatterns();
    String[] patterns = new String[defaultPatterns.size()];

    int i = 0;
    for (String pattern : defaultPatterns) {
      patterns[i] = getPath(pattern);
      paths.add(pattern);
      i++;
    }
    PatternsRequestCondition patternsInfo = new PatternsRequestCondition(patterns);

    ParamsRequestCondition paramsInfo = defaultMapping.getParamsCondition();
    if (!approvalParameter.equals(OAuth2Utils.USER_OAUTH_APPROVAL)
        && defaultPatterns.contains("/oauth/authorize")) {
      String[] params = new String[paramsInfo.getExpressions().size()];
      Set<NameValueExpression<String>> expressions = paramsInfo.getExpressions();
      i = 0;
      for (NameValueExpression<String> expression : expressions) {
        String param = expression.toString();
        if (OAuth2Utils.USER_OAUTH_APPROVAL.equals(param)) {
          params[i] = approvalParameter;
        } else {
          params[i] = param;
        }
        i++;
      }
      paramsInfo = new ParamsRequestCondition(params);
    }

    RequestMappingInfo mapping =
        new RequestMappingInfo(
            patternsInfo,
            defaultMapping.getMethodsCondition(),
            paramsInfo,
            defaultMapping.getHeadersCondition(),
            defaultMapping.getConsumesCondition(),
            defaultMapping.getProducesCondition(),
            defaultMapping.getCustomCondition());
    return mapping;
  }