2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.parser.spi.source;
11 import java.net.URISyntaxException;
12 import java.util.HashMap;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
17 * Map-based {@link PrefixToModule} namespace. This class is NOT thread-safe.
19 public class PrefixToModuleMap implements PrefixToModule {
20 private final Map<String, QNameModule> prefixToModuleMap = new HashMap<>();
21 private final Map<URI, QNameModule> namespaceToModuleMap = new HashMap<>();
23 public void put(final String prefix, final QNameModule module) {
24 prefixToModuleMap.put(prefix, module);
25 namespaceToModuleMap.put(module.getNamespace(), module);
29 public QNameModule get(final String prefix) {
30 return prefixToModuleMap.get(prefix);
34 public QNameModule getByNamespace(final String namespace) throws URISyntaxException {
35 return namespaceToModuleMap.get(new URI(namespace));