Add missing license headers to packetcable-driver objects
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / objects / PCMMResourceSet.java
1 /*
2  * Copyright (c) 2014 Cable Television Laboratories, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.pcmm.objects;
10
11 import java.util.HashMap;
12 import java.util.Map;
13
14 /**
15  * This stores and handles the PCMM resources.
16  *
17  */
18 public class PCMMResourceSet {
19
20     private Map<Object, PCMMResourcesMapper<?, ?>> mapper;
21
22     private static PCMMResourceSet instance;
23
24     private PCMMResourceSet() {
25         mapper = new HashMap<Object, PCMMResourcesMapper<?, ?>>();
26     }
27
28     public static PCMMResourceSet getInstance() {
29         if (instance == null)
30             instance = new PCMMResourceSet();
31         return instance;
32     }
33
34     /**
35      * adds a new mapping
36      *
37      * @param key
38      *            to be used for identifying mapped structure
39      * @return resource mapper
40      */
41     @SuppressWarnings("unchecked")
42     public <M, T extends PCMMResource> PCMMResourcesMapper<M, T> getMappedResources(
43         Object key) {
44         return (PCMMResourcesMapper<M, T>) mapper.get(key);
45     }
46
47     public <M, T extends PCMMResource> void mapResources(Object key,
48             PCMMResourcesMapper<M, T> resources) {
49         mapper.put(key, resources);
50     }
51
52     public void removeMapping(Object key) {
53         mapper.remove(key);
54     }
55
56     public void removeAllMappings() {
57         mapper.clear();
58     }
59
60 }