Align createQName @Nonnull declarations
[yangtools.git] / yang / yang-data-codec-gson / src / main / java / org / opendaylight / yangtools / yang / data / codec / gson / RFC7951JSONInstanceIdentifierCodec.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies, s.r.o. 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.data.codec.gson;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.common.QNameModule;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 final class RFC7951JSONInstanceIdentifierCodec extends JSONInstanceIdentifierCodec {
19     RFC7951JSONInstanceIdentifierCodec(final SchemaContext context, final JSONCodecFactory jsonCodecFactory) {
20         super(context, jsonCodecFactory);
21     }
22
23     @Override
24     protected StringBuilder appendQName(final StringBuilder sb, final QName qname,
25             final @Nullable QNameModule lastModule) {
26         if (qname.getModule().equals(lastModule)) {
27             return sb.append(qname.getLocalName());
28         }
29
30         return super.appendQName(sb, qname, lastModule);
31     }
32
33     @Override
34     protected QName createQName(final @Nonnull QNameModule lastModule, final String localName) {
35         checkArgument(lastModule != null, "Unprefixed leading name %s", localName);
36         return QName.create(lastModule, localName);
37     }
38 }