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

com.hubspot.horizon.Headers Maven / Gradle / Ivy

There is a newer version: 0.3.0
Show newest version
package com.hubspot.horizon;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;

public class Headers implements Iterable
{ private final List
headerList; private final LinkedHashMap> headerMap; public Headers(List
headers) { this.headerList = headers; this.headerMap = new LinkedHashMap>(); for (Header header : headers) { String key = header.getName().toLowerCase(); if (headerMap.containsKey(key)) { headerMap.get(key).add(header.getValue()); } else { headerMap.put(key, Lists.newArrayList(header.getValue())); } } } @Override public Iterator
iterator() { return headerList.iterator(); } public List get(String name) { List headers = headerMap.get(Preconditions.checkNotNull(name).toLowerCase()); return headers == null ? Collections.emptyList() : headers; } @Nullable public String getFirst(String name) { List headers = get(Preconditions.checkNotNull(name).toLowerCase()); return headers.isEmpty() ? null : headers.get(0); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy