/**
* Copyright (C) 2003-2008 eXo Platform SAS.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see<http://www.gnu.org/licenses/>.
*/
package org.etk.core.rest.util;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.MediaType;
import org.etk.core.rest.ExtMultivaluedMap;
public class MediaTypeMultivaluedMap<V> extends MediaTypeMap<List<V>> implements ExtMultivaluedMap<MediaType, V> {
/**
* Generated by Eclipse.
*/
private static final long serialVersionUID = 7082102018450744774L;
/**
* Get {@link List} with specified key. If it does not exist new one be
* created.
*
* @param mediaType MediaType
* @return List of ProviderFactory if no value mapped to the specified key
* then empty list will be returned instead null
*/
public List<V> getList(MediaType mediaType) {
List<V> l = get(mediaType);
if (l == null) {
l = new ArrayList<V>();
put(mediaType, l);
}
return l;
}
/**
* {@inheritDoc}
*/
public void add(MediaType mediaType, V value) {
if (value == null)
return;
List<V> list = getList(mediaType);
list.add(value);
}
/**
* {@inheritDoc}
*/
public V getFirst(MediaType mime) {
List<V> list = get(mime);
return list != null && list.size() > 0 ? list.get(0) : null;
}
/**
* {@inheritDoc}
*/
public void putSingle(MediaType mediaType, V value) {
if (value == null)
return;
List<V> list = getList(mediaType);
list.clear();
list.add(value);
}
}