df19d31ff6ba6c053c28da5a1164525f0d93c094
[mdsal.git] / binding / yang-binding / src / main / java / org / opendaylight / yangtools / yang / binding / KeyedInstanceIdentifierV2.java
1 /*
2  * Copyright (c) 2018 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.binding;
9
10 import java.io.IOException;
11 import java.io.ObjectInput;
12 import java.io.ObjectOutput;
13 import java.io.ObjectStreamException;
14 import java.io.Serial;
15 import org.eclipse.jdt.annotation.Nullable;
16
17 final class KeyedInstanceIdentifierV2<T extends KeyAware<K> & DataObject, K extends Key<T>>
18         extends InstanceIdentifierV3<T> {
19     @Serial
20     private static final long serialVersionUID = 2L;
21
22     private @Nullable K key;
23
24     @SuppressWarnings("redundantModifier")
25     public KeyedInstanceIdentifierV2() {
26         // For Externalizable
27     }
28
29     KeyedInstanceIdentifierV2(final KeyedInstanceIdentifier<T, K> source) {
30         super(source);
31         key = source.getKey();
32     }
33
34     @Override
35     public void writeExternal(final ObjectOutput out) throws IOException {
36         super.writeExternal(out);
37         out.writeObject(key);
38     }
39
40     @Override
41     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
42         super.readExternal(in);
43         key = (K) in.readObject();
44     }
45
46     @Serial
47     @Override
48     Object readResolve() throws ObjectStreamException {
49         return new KeyedInstanceIdentifier<>(getTargetType(), getPathArguments(), isWildcarded(), getHash(), key);
50     }
51 }