Bug 3875: Introduced transforming stream writer
[yangtools.git] / yang / yang-data-transform / src / main / java / org / opendaylight / yangtools / transform / QNameModuleReplacementFunction.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.transform;
9
10 import com.google.common.base.Function;
11 import com.google.common.base.Preconditions;
12 import java.util.Map;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.common.QNameModule;
15
16 class QNameModuleReplacementFunction implements Function<QName, QName> {
17
18     private final Map<QNameModule, QNameModule> mapping;
19
20     QNameModuleReplacementFunction(Map<QNameModule, QNameModule> mapping) {
21         this.mapping = Preconditions.checkNotNull(mapping);
22     }
23
24     @Override
25     public QName apply(QName input) {
26         QNameModule potential = mapping.get(input.getModule());
27         if (potential != null) {
28             return QName.cachedReference(QName.create(potential, input.getLocalName()));
29         }
30         return input;
31     }
32
33 }