Populate data/ hierarchy
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / NIPv1.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, 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.api;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.util.Map;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
19
20 /**
21  * Externalizable proxy for {@link NodeIdentifierWithPredicates}.
22  *
23  * @deprecated Since 4.0.0 in favor of {@link NIPv2}.
24  */
25 @Deprecated(since = "4.0.0", forRemoval = true)
26 final class NIPv1 implements Externalizable {
27     private static final long serialVersionUID = 1L;
28
29     private NodeIdentifierWithPredicates nip;
30
31     @SuppressWarnings("checkstyle:redundantModifier")
32     public NIPv1() {
33         // For Externalizable
34     }
35
36     NIPv1(final NodeIdentifierWithPredicates nid) {
37         this.nip = requireNonNull(nid);
38     }
39
40     @Override
41     public void writeExternal(final ObjectOutput out) throws IOException {
42         nip.getNodeType().writeTo(out);
43         out.writeObject(nip.asMap());
44     }
45
46     @Override
47     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
48         final QName qname = QName.readFrom(in);
49         nip = NodeIdentifierWithPredicates.of(qname, (Map<QName, Object>) in.readObject());
50     }
51
52     private Object readResolve() {
53         return nip;
54     }
55 }