Remove javax.annotation nullness annotations
[netconf.git] / restconf / restconf-nb-bierman02 / src / main / java / org / opendaylight / netconf / sal / rest / impl / StringModuleInstanceIdentifierCodec.java
1 /*
2  * Copyright (c) 2016 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.netconf.sal.rest.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.net.URI;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.util.AbstractModuleStringInstanceIdentifierCodec;
15 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
18
19 /**
20  * Codec for module instance identifiers.
21  *
22  * @deprecated This class will be replaced by StringModuleInstanceIdentifierCodec from restconf-nb-rfc8040
23  */
24 @Deprecated
25 public final class StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
26
27     private final DataSchemaContextTree dataContextTree;
28     private final SchemaContext context;
29     private final String defaultPrefix;
30
31     public StringModuleInstanceIdentifierCodec(final SchemaContext context) {
32         this.context = requireNonNull(context);
33         this.dataContextTree = DataSchemaContextTree.from(context);
34         this.defaultPrefix = "";
35     }
36
37     StringModuleInstanceIdentifierCodec(final SchemaContext context, final @NonNull String defaultPrefix) {
38         this.context = requireNonNull(context);
39         this.dataContextTree = DataSchemaContextTree.from(context);
40         this.defaultPrefix = defaultPrefix;
41     }
42
43     @Override
44     protected Module moduleForPrefix(final String prefix) {
45         if (prefix.isEmpty() && !this.defaultPrefix.isEmpty()) {
46             return this.context.findModules(this.defaultPrefix).stream().findFirst().orElse(null);
47         } else {
48             return this.context.findModules(prefix).stream().findFirst().orElse(null);
49         }
50     }
51
52     @Override
53     protected DataSchemaContextTree getDataContextTree() {
54         return this.dataContextTree;
55     }
56
57     @Override
58     protected String prefixForNamespace(final URI namespace) {
59         return this.context.findModules(namespace).stream().findFirst().map(Module::getName).orElse(null);
60     }
61 }