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

java.com.ionic.sdk.httpclient.HttpHeaders Maven / Gradle / Ivy

Go to download

The Ionic Java SDK provides an easy-to-use interface to the Ionic Platform.

There is a newer version: 2.9.0
Show newest version
package com.ionic.sdk.httpclient;

import com.ionic.sdk.core.value.Value;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * The set of name value pairs associated with an HTTP request / response.
 */
public class HttpHeaders extends ArrayList {

    /**
     * Constructor.
     *
     * @param httpHeaders pre-composed objects to be added to the initial backing collection
     */
    public HttpHeaders(final HttpHeader... httpHeaders) {
        this.addAll(Arrays.asList(httpHeaders));
    }

    /**
     * Return the value of the contained http header associated with the specified name.
     *
     * @param name the label of the sought header entry
     * @return the value of the corresponding header entry
     */
    public final String getHeaderValue(final String name) {
        final HttpHeader httpHeader = getHeader(name);
        return ((httpHeader == null) ? null : httpHeader.getValue());
    }

    /**
     * Return the contained http header associated with the specified name.
     *
     * @param name the label of the sought header entry
     * @return the corresponding header entry
     */
    private HttpHeader getHeader(final String name) {
        HttpHeader httpHeader = null;
        for (final HttpHeader httpHeaderIt : this) {
            if (Value.isEqualIgnoreCase(httpHeaderIt.getName(), name)) {
                httpHeader = httpHeaderIt;
                break;
            }
        }
        return httpHeader;
    }

    /**
     * Return an enumeration of header names contained in this collection of headers.
     *
     * @return a collection of strings representing the names of the contained headers
     */
    public final Collection headerNames() {
        final Collection headerNames = new ArrayList();
        for (final HttpHeader httpHeader : this) {
            final String name = httpHeader.getName();
            if (name != null) {
                headerNames.add(name);
            }
        }
        return headerNames;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy