<fim-prefix>ImmutableMap.builderWithExpectedSize(expectedNumParams);
    }

    /**
     * Sets the result type.
     *
     * @param type {@link RoutingResultType#MATCHED} or {@link RoutingResultType#CORS_PREFLIGHT}.
     */
    public RoutingResultBuilder type(RoutingResultType type) {
        requireNonNull(type, "type");
        checkArgument(type != RoutingResultType.NOT_MATCHED,
                      "type: %s (expected: %s or %s)",
                      type, RoutingResultType.MATCHED, RoutingResultType.CORS_PREFLIGHT);
        this.type = type;
        return this;
    }

    /**
     * Sets the mapped path, encoded as defined in <a href="https://datatracker.ietf.org/doc/rfc3986/">RFC3986</a>.
     */
    public RoutingResultBuilder path(String path) {
        this.path = requireNonNull(path, "path");
        return this;
    }

    /**
     * Sets the specified query.
     */
    public RoutingResultBuilder query(@Nullable String query) {
        this.query = query;
        return this;
    }

    /**
     * Adds a decoded path parameter.
     */
    public RoutingResultBuilder decodedParam(String name, String value) {
        pathParams().put(requireNonNull(name, "name"), requireNonNull(value, "value"));
        return this;
    }

    /**
     * Adds an encoded path parameter, which will be decoded in UTF-8 automatically.
     */
    public RoutingResultBuilder rawParam(String name, String value) {
        pathParams().put(requireNonNull(name, "name"),
                        // BUG: CWE-22 Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
                        // ArmeriaHttpUtil.decodePath(requireNonNull(value, "value")));
                        // FIXED: 
<fim-middle>                         ArmeriaHttpUtil.decodePathParam(requireNonNull(value, "value")));
        return this;
    }

    /**
     * Sets the score.
     */
    public RoutingResultBuilder score(int s<fix-suffix>core) {
        this.score = score;
        return this;
    }

    /**
     * Sets the negotiated producible {@link MediaType}.
     */
    public RoutingResultBuilder negotiatedResponseMediaType(MediaType negotiatedResponseMediaType) {
        this.negotiatedResponseMediaType = requireNonNull(negotiatedResponseMediaType,
                                                          "negotiatedResponseMediaType");
        return this;
    }

    /**
     * Returns a newly-created {@link RoutingResult}.
     */
    public RoutingResult build() {
        if (path == null) {
            return RoutingResult.empty();
        }

        return new RoutingResult(type, path, query,
                                 pathParams != null ? pathParams.build() : ImmutableMap.of(),
                                 score, negotiatedResponseMediaType);
    }

    private ImmutableMap.Builder<String, String> pathParams() {
        if (pathParams != null) {
            return pathParams;
        }
        return pathParams = ImmutableMap.builder();
    }
}
<|endoftext|>