All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.linecorp.armeria.common.HttpParameters Maven / Gradle / Ivy

/*
 * Copyright 2017 LINE Corporation
 *
 * LINE Corporation licenses this file to you under the Apache License,
 * version 2.0 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at:
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.linecorp.armeria.common;

import static java.util.Objects.requireNonNull;

import java.util.Map;

import io.netty.handler.codec.Headers;

/**
 * HTTP parameters map.
 */
public interface HttpParameters extends Headers {

    /**
     * An immutable empty HTTP parameters map.
     */
    HttpParameters EMPTY_PARAMETERS = of().asImmutable();

    /**
     * Returns a new empty HTTP parameters map.
     */
    static HttpParameters of() {
        return new DefaultHttpParameters();
    }

    /**
     * Returns a new HTTP parameters map with the specified {@code Map>}.
     */
    static HttpParameters copyOf(Map> parameters) {
        requireNonNull(parameters, "parameters");
        final HttpParameters httpParameters = new DefaultHttpParameters();
        parameters.forEach((name, values) ->
                                   values.forEach(value -> httpParameters.add(name, value)));
        return httpParameters;
    }

    /**
     * Returns a copy of the specified {@code Headers}.
     */
    static HttpParameters copyOf(Headers parameters) {
        return of().set(requireNonNull(parameters, "parameters"));
    }

    /**
     * Returns the immutable view of this parameters map.
     */
    default HttpParameters asImmutable() {
        return new ImmutableHttpParameters(this);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy