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

io.airlift.jaxrs.testing.GuavaMultivaluedMap Maven / Gradle / Ivy

There is a newer version: 285
Show newest version
package io.airlift.jaxrs.testing;

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ForwardingMap;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import jakarta.ws.rs.core.MultivaluedMap;

import java.util.List;
import java.util.Map;

public class GuavaMultivaluedMap
        extends ForwardingMap>
        implements MultivaluedMap
{
    private final ListMultimap multimap = ArrayListMultimap.create();

    public GuavaMultivaluedMap()
    {
    }

    public GuavaMultivaluedMap(Multimap multimap)
    {
        this.multimap.putAll(multimap);
    }

    @Override
    public void putSingle(K key, V value)
    {
        multimap.removeAll(key);
        multimap.put(key, value);
    }

    @Override
    protected Map> delegate()
    {
        return Multimaps.asMap(multimap);
    }

    @Override
    public void add(K key, V value)
    {
        multimap.put(key, value);
    }

    @SafeVarargs
    @Override
    public final void addAll(K key, V... newValues)
    {
        multimap.putAll(key, ImmutableList.copyOf(newValues));
    }

    @Override
    public void addAll(K key, List valueList)
    {
        multimap.putAll(key, valueList);
    }

    @Override
    public V getFirst(K key)
    {
        return multimap.get(key).stream().findFirst().orElse(null);
    }

    @Override
    public void addFirst(K key, V value)
    {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean equalsIgnoreValueOrder(MultivaluedMap otherMap)
    {
        throw new UnsupportedOperationException();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy