org.jboss.resteasy.util.PrefixedMultivaluedMap Maven / Gradle / Ivy
package org.jboss.resteasy.util;
import javax.ws.rs.core.MultivaluedMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* {@link javax.ws.rs.core.MultivaluedMap} implementation that wraps another instance and only returns values that are prefixed with the given {@link #prefixWithDot}.
*
* @param The type of the values in the lists in the map.
*/
public class PrefixedMultivaluedMap extends DelegatingMultivaluedMap
{
private final String prefixWithDot;
/**
* Constructor setting the prefix and the delegate.
* @param prefix prefix
* @param delegate delegate map
*/
public PrefixedMultivaluedMap(final String prefix, final MultivaluedMap delegate)
{
super(delegate);
this.prefixWithDot = prefix + ".";
}
/**
* Returns the value assigned to "prefix.key" implicitly converts the key to {@link String}.
* @param key key
* @return values
*/
@Override
public List get(Object key)
{
return super.get(prefixWithDot + key);
}
@Override
public Set keySet()
{
HashSet result = new HashSet();
for (String key : super.keySet())
{
if (key.startsWith(prefixWithDot))
{
result.add(key.substring(prefixWithDot.length()));
}
}
return result;
}
}