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