Switch to Objects.requireNonNull
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / main / java / org / opendaylight / mdsal / binding / dom / adapter / invoke / LocalNameRpcServiceInvoker.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.mdsal.binding.dom.adapter.invoke;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.lang.reflect.Method;
13 import java.util.HashMap;
14 import java.util.Map;
15 import java.util.Map.Entry;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.common.QNameModule;
18
19 final class LocalNameRpcServiceInvoker extends AbstractMappedRpcInvoker<String> {
20     private final QNameModule module;
21
22     private LocalNameRpcServiceInvoker(final QNameModule module, final Map<String, Method> map) {
23         super(map);
24         this.module = requireNonNull(module);
25     }
26
27     static RpcServiceInvoker instanceFor(final QNameModule module, final Map<QName, Method> qnameToMethod) {
28         final Map<String, Method> map = new HashMap<>();
29         for (Entry<QName, Method> e : qnameToMethod.entrySet()) {
30             map.put(e.getKey().getLocalName(), e.getValue());
31         }
32
33         return new LocalNameRpcServiceInvoker(module, map);
34     }
35
36     @Override
37     protected String qnameToKey(final QName qname) {
38         if (module.equals(qname.getModule())) {
39             return qname.getLocalName();
40         } else {
41             return null;
42         }
43     }
44 }