7a5ca7debe8c3d4379e1c03812afcabac3ee1390
[controller.git] / opendaylight / config / yang-store-impl / src / main / java / org / opendaylight / controller / config / yang / store / impl / YangStoreSnapshotImpl.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, 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 package org.opendaylight.controller.config.yang.store.impl;
9
10 import org.opendaylight.controller.config.yang.store.api.YangStoreSnapshot;
11 import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
12 import org.opendaylight.yangtools.yang.model.api.Module;
13
14 import java.util.Collections;
15 import java.util.Map;
16 import java.util.Map.Entry;
17
18 public class YangStoreSnapshotImpl implements YangStoreSnapshot {
19
20     private final Map<String /* Namespace from yang file */,
21             Map<String /* Name of module entry from yang file */, ModuleMXBeanEntry>> moduleMXBeanEntryMap;
22
23     private final Map<String, Entry<Module, String>> moduleMap;
24
25     public YangStoreSnapshotImpl(
26             Map<String, Map<String, ModuleMXBeanEntry>> moduleMXBeanEntryMap,
27             Map<String, Entry<Module, String>> moduleMap) {
28         this.moduleMXBeanEntryMap = Collections.unmodifiableMap(moduleMXBeanEntryMap);
29         this.moduleMap = Collections.unmodifiableMap(moduleMap);
30     }
31
32     public YangStoreSnapshotImpl(YangStoreSnapshotImpl yangStoreSnapshot) {
33         this.moduleMXBeanEntryMap = yangStoreSnapshot.moduleMXBeanEntryMap;
34         this.moduleMap = yangStoreSnapshot.moduleMap;
35     }
36
37     @Override
38     public Map<String, Map<String, ModuleMXBeanEntry>> getModuleMXBeanEntryMap() {
39         return moduleMXBeanEntryMap;
40     }
41
42     @Override
43     public Map<String, Entry<Module, String>> getModuleMap() {
44         return moduleMap;
45     }
46
47     @Override
48     public int countModuleMXBeanEntries() {
49         int i = 0;
50         for (Map<String, ModuleMXBeanEntry> value : moduleMXBeanEntryMap
51                 .values()) {
52             i += value.keySet().size();
53         }
54         return i;
55     }
56
57     @Override
58     public void close() {
59         // TODO: reference counting
60     }
61
62 }