2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019-2021 Nordix Foundation
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ========================LICENSE_END===================================
21 package org.oran.dmaapadapter.repository;
23 import java.util.Collection;
24 import java.util.Collections;
25 import java.util.HashMap;
27 import java.util.Vector;
30 * A map, where each key can be bound to may values (where each value has an own
33 public class MultiMap<T> {
35 private final Map<String, Map<String, T>> map = new HashMap<>();
37 public void put(String key, String id, T value) {
38 this.map.computeIfAbsent(key, k -> new HashMap<>()).put(id, value);
41 public T remove(String key, String id) {
42 Map<String, T> innerMap = this.map.get(key);
43 if (innerMap != null) {
44 T removedElement = innerMap.remove(id);
45 if (innerMap.isEmpty()) {
48 return removedElement;
53 public Collection<T> get(String key) {
54 Map<String, T> innerMap = this.map.get(key);
55 if (innerMap == null) {
56 return Collections.emptyList();
58 return new Vector<>(innerMap.values());