2 * Copyright (c) 2017 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.common.util;
10 import java.util.Arrays;
11 import java.util.Collection;
12 import java.util.HashMap;
13 import java.util.LinkedList;
14 import java.util.List;
16 import java.util.Objects;
18 import javax.ws.rs.core.MultivaluedMap;
21 * A hash table based implementation of {@link MultivaluedMap} interface.
23 * @deprecated Use {@link javax.ws.rs.core.MultivaluedHashMap} instead.
24 * @author Thomas Pantelis
26 @Deprecated(since = "2.0.1", forRemoval = true)
27 // FIXME: 3.0.0: remove this class
28 public class MultivaluedHashMap<K, V> implements MultivaluedMap<K, V> {
29 private final Map<K, List<V>> store = new HashMap<>();
32 public final void putSingle(K key, V value) {
33 List<V> values = getValues(key);
42 public void add(K key, V value) {
43 List<V> values = getValues(key);
52 public final void addAll(K key, V... newValues) {
53 addAll(key, Arrays.asList(newValues));
57 public void addAll(K key, List<V> valueList) {
58 Objects.requireNonNull(valueList, "Supplied list of values must not be null.");
60 if (valueList.isEmpty()) {
64 List<V> values = getValues(key);
65 for (V value : valueList) {
73 public void addFirst(K key, V value) {
74 List<V> values = getValues(key);
82 public V getFirst(K key) {
83 List<V> values = store.get(key);
84 return values == null || values.isEmpty() ? null : values.get(0);
88 public boolean equalsIgnoreValueOrder(MultivaluedMap<K, V> omap) {
92 if (!keySet().equals(omap.keySet())) {
95 for (Entry<K, List<V>> e : entrySet()) {
96 List<V> olist = omap.get(e.getKey());
97 if (e.getValue().size() != olist.size()) {
100 for (V v : e.getValue()) {
101 if (!olist.contains(v)) {
110 public Collection<List<V>> values() {
111 return store.values();
120 public List<V> remove(Object key) {
121 return store.remove(key);
125 public void putAll(Map<? extends K, ? extends List<V>> map) {
130 public List<V> put(K key, List<V> value) {
131 return store.put(key, value);
135 public Set<K> keySet() {
136 return store.keySet();
140 public boolean isEmpty() {
141 return store.isEmpty();
145 public List<V> get(Object key) {
146 return store.get(key);
150 public Set<Entry<K, List<V>>> entrySet() {
151 return store.entrySet();
155 public boolean containsValue(Object value) {
156 return store.containsValue(value);
160 public boolean containsKey(Object key) {
161 return store.containsKey(key);
165 public void clear() {
169 private List<V> getValues(K key) {
170 return store.computeIfAbsent(key, k -> new LinkedList<>());