Remove PrefixToModule.isPreLinkageMap()
[yangtools.git] / yang / yang-parser-spi / src / main / java / org / opendaylight / yangtools / yang / parser / spi / source / PrefixToModuleMap.java
1 /*
2  * Copyright (c) 2015 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.yangtools.yang.parser.spi.source;
9
10 import java.net.URI;
11 import java.net.URISyntaxException;
12 import java.util.HashMap;
13 import java.util.Map;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15
16 /**
17  * Map-based {@link PrefixToModule} namespace. This class is NOT thread-safe.
18  */
19 public class PrefixToModuleMap implements PrefixToModule {
20     private final Map<String, QNameModule> prefixToModuleMap = new HashMap<>();
21     private final Map<URI, QNameModule> namespaceToModuleMap = new HashMap<>();
22
23     public void put(final String prefix, final QNameModule module) {
24         prefixToModuleMap.put(prefix, module);
25         namespaceToModuleMap.put(module.getNamespace(), module);
26     }
27
28     @Override
29     public QNameModule get(final String prefix) {
30         return prefixToModuleMap.get(prefix);
31     }
32
33     @Override
34     public QNameModule getByNamespace(final String namespace) throws URISyntaxException {
35         return namespaceToModuleMap.get(new URI(namespace));
36     }
37 }