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

org.jboss.resteasy.specimpl.UnmodifiableMultivaluedMap Maven / Gradle / Ivy

There is a newer version: 4.0.0.Beta5
Show newest version
package org.jboss.resteasy.specimpl;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.ws.rs.core.MultivaluedMap;

/**
 * Unmodifiable implementation of {@link javax.ws.rs.core.MultivaluedMap} interface
 *
 * @author Martin Stefanko
 * @version $Revision: 1 $
 */
public class UnmodifiableMultivaluedMap implements MultivaluedMap
{

   private final MultivaluedMap delegate;

   private final Set>> entrySet;

   public UnmodifiableMultivaluedMap(final MultivaluedMap delegate)
   {
      this.delegate = delegate;
      this.entrySet = buildEntrySet();
   }

   private Set>> buildEntrySet()
   {
      Set>> entrySetDelegator = delegate.entrySet();
      if (entrySetDelegator == null)
      {
         return null;
      }
      Set>> entrySetToReturn = new HashSet<>();
      for (final java.util.Map.Entry> entry : entrySetDelegator)
      {
         entrySetToReturn.add(new Entry>()
         {

            @Override
            public K getKey()
            {
               return entry.getKey();
            }

            @Override
            public List getValue()
            {
               List value = entry.getValue();
               return value == null ? null : Collections.unmodifiableList(value);
            }

            @Override
            public List setValue(List value)
            {
               throw new UnsupportedOperationException();
            }
         });
      }
      return Collections.unmodifiableSet(entrySetToReturn);
   }

   @Override
   public void putSingle(K k, V v)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public void add(K k, V v)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public V getFirst(K key)
   {
      return delegate.getFirst(key);
   }

   @SuppressWarnings(value = "unchecked")
   @Override
   public void addAll(K k, V... vs)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public void addAll(K k, List list)
   {
      throw new UnsupportedOperationException();
   }

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

   @Override
   public boolean equalsIgnoreValueOrder(MultivaluedMap omap)
   {
      return delegate.equalsIgnoreValueOrder(omap);
   }

   @Override
   public void clear()
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public Set>> entrySet()
   {
      return this.entrySet;
   }

   @Override
   public List get(Object key)
   {
      List list = delegate.get(key);
      return list == null ? null : Collections.unmodifiableList(list);
   }

   @Override
   public Set keySet()
   {
      return Collections.unmodifiableSet(delegate.keySet());
   }

   @Override
   public List put(K key, List value)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public void putAll(Map> m)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public List remove(Object key)
   {
      throw new UnsupportedOperationException();
   }

   @Override
   public Collection> values()
   {
      return Collections.unmodifiableCollection(delegate.values());
   }

   @Override
   public boolean containsKey(Object o)
   {
      return delegate.containsKey(o);
   }

   @Override
   public boolean containsValue(Object o)
   {
      return delegate.containsValue(o);
   }

   @Override
   public int size()
   {
      return delegate.size();
   }

   @Override
   public boolean isEmpty()
   {
      return delegate.isEmpty();
   }

   @Override
   public String toString()
   {
      return delegate.toString();
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy