2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
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.openecomp.sdc.be.dao.utils;
23 import java.util.HashMap;
26 public class TypeMap {
27 private Map<Class<? extends Object>, Map<String, Object>> cacheMap = new HashMap<>();
29 private Map<String, Object> getMap(Class<? extends Object> clazz) {
30 Map<String, Object> map = cacheMap.get(clazz);
32 cacheMap.put(clazz, new HashMap<>());
34 return cacheMap.get(clazz);
38 * put an object (value) in it's type map using the given key.
41 * The key inside the type map.
43 * The object to insert (based on it's type and the given key).
45 public void put(String key, Object value) {
46 getMap(value.getClass()).put(key, value);
50 * Get the cached object based on it's type and key.
56 * @return The object that match the given type and key or null if none
59 @SuppressWarnings("unchecked")
60 public <T> T get(Class<T> clazz, String key) {
61 return (T) (cacheMap.get(clazz) == null ? null : cacheMap.get(clazz).get(key));