package org.springframework.http.server.reactive;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.http.HttpField;
import org.eclipse.jetty.http.HttpFields;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
import org.springframework.util.MultiValueMap;
class implements MultiValueMap<String, String> {
private final HttpFields ;
(HttpFields headers) {
this.headers = headers;
}
@Override
public String (String key) {
return this.headers.get(key);
}
@Override
public void (String key, @Nullable String value) {
this.headers.add(key, value);
}
@Override
public void (String key, List<? extends String> values) {
values.forEach(value -> add(key, value));
}
@Override
public void (MultiValueMap<String, String> values) {
values.forEach(this::addAll);
}
@Override
public void (String key, @Nullable String value) {
this.headers.put(key, value);
}
@Override
public void (Map<String, String> values) {
values.forEach(this::set);
}
@Override
public Map<String, String> () {
Map<String, String> singleValueMap = new LinkedHashMap<>(this.headers.size());
Iterator<HttpField> iterator = this.headers.iterator();
iterator.forEachRemaining(field -> {
if (!singleValueMap.containsKey(field.getName())) {
singleValueMap.put(field.getName(), field.getValue());
}
});
return singleValueMap;
}
@Override
public int () {
return this.headers.getFieldNamesCollection().size();
}
@Override
public boolean () {
return (this.headers.size() == 0);
}
@Override
public boolean (Object key) {
return (key instanceof String && this.headers.containsKey((String) key));
}
@Override
public boolean (Object value) {
return (value instanceof String &&
this.headers.stream().anyMatch(field -> field.contains((String) value)));
}
@Nullable
@Override
public List<String> (Object key) {
if (containsKey(key)) {
return this.headers.getValuesList((String) key);
}
return null;
}
@Nullable
@Override
public List<String> (String key, List<String> value) {
List<String> oldValues = get(key);
this.headers.put(key, value);
return oldValues;
}
@Nullable
@Override
public List<String> (Object key) {
if (key instanceof String) {
List<String> oldValues = get(key);
this.headers.remove((String) key);
return oldValues;
}
return null;
}
@Override
public void (Map<? extends String, ? extends List<String>> map) {
map.forEach(this::put);
}
@Override
public void () {
this.headers.clear();
}
@Override
public Set<String> () {
return this.headers.getFieldNamesCollection();
}
@Override
public Collection<List<String>> () {
return this.headers.getFieldNamesCollection().stream()
.map(this.headers::getValuesList).collect(Collectors.toList());
}
@Override
public Set<Entry<String, List<String>>> () {
return new AbstractSet<Entry<String, List<String>>>() {
@Override
public Iterator<Entry<String, List<String>>> () {
return new EntryIterator();
}
@Override
public int () {
return headers.size();
}
};
}
@Override
public String () {
return HttpHeaders.formatHeaders(this);
}
private class implements Iterator<Entry<String, List<String>>> {
private Enumeration<String> = headers.getFieldNames();
@Override
public boolean () {
return this.names.hasMoreElements();
}
@Override
public Entry<String, List<String>> () {
return new HeaderEntry(this.names.nextElement());
}
}
private class implements Entry<String, List<String>> {
private final String ;
(String key) {
this.key = key;
}
@Override
public String () {
return this.key;
}
@Override
public List<String> () {
return headers.getValuesList(this.key);
}
@Override
public List<String> (List<String> value) {
List<String> previousValues = headers.getValuesList(this.key);
headers.put(this.key, value);
return previousValues;
}
}
}