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

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

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

import javax.ws.rs.core.MultivaluedMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Bill Burke
 * @version $Revision: 1 $
 */
@SuppressWarnings("serial")
public class MultivaluedMapImpl extends HashMap> implements MultivaluedMap
{
   public void putSingle(K key, V value)
   {
      List list = new ArrayList();
      list.add(value);
      put(key, list);
   }

   @Override
   public void addAll(K key, V... newValues)
   {
      for (V value : newValues)
      {
         add(key, value);
      }
   }

   @Override
   public void addAll(K key, List valueList)
   {
      for (V value : valueList)
      {
         add(key, value);
      }
   }

   @Override
   public void addFirst(K key, V value)
   {
      List list = get(key);
      if (list == null)
      {
         add(key, value);
         return;
      }
      else
      {
         list.add(0, value);
      }
   }
   public final void add(K key, V value)
   {
      getList(key).add(value);
   }


   public final void addMultiple(K key, Collection values)
   {
      getList(key).addAll(values);
   }

   public V getFirst(K key)
   {
      List list = get(key);
      return list == null ? null : list.get(0);
   }

   public final List getList(K key)
   {
      List list = get(key);
      if (list == null)
         put(key, list = new ArrayList());
      return list;
   }

   public void addAll(MultivaluedMapImpl other)
   {
      for (Map.Entry> entry : other.entrySet())
      {
         getList(entry.getKey()).addAll(entry.getValue());
      }
   }

   @Override
   public boolean equalsIgnoreValueOrder(MultivaluedMap omap) {
      if (this == omap) {
         return true;
      }
      if (!keySet().equals(omap.keySet())) {
         return false;
      }
      for (Map.Entry> e : entrySet()) {
         List olist = omap.get(e.getKey());
         if (e.getValue().size() != olist.size()) {
            return false;
         }
         for (V v : e.getValue()) {
            if (!olist.contains(v)) {
               return false;
            }
         }
      }
      return true;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy