Fix identityref wildcards
[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 org.eclipse.jdt.annotation.Nullable;
15
16 final class KeyedInstanceIdentifierV2<T extends Identifiable<K> & DataObject, K extends Identifier<T>>
17         extends InstanceIdentifierV3<T> {
18     private static final long serialVersionUID = 2L;
19
20     private @Nullable K key;
21
22     @SuppressWarnings("redundantModifier")
23     public KeyedInstanceIdentifierV2() {
24         // For Externalizable
25     }
26
27     KeyedInstanceIdentifierV2(final KeyedInstanceIdentifier<T, K> source) {
28         super(source);
29         key = source.getKey();
30     }
31
32     @Override
33     public void writeExternal(final ObjectOutput out) throws IOException {
34         super.writeExternal(out);
35         out.writeObject(key);
36     }
37
38     @Override
39     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
40         super.readExternal(in);
41         key = (K) in.readObject();
42     }
43
44     @Override
45     Object readResolve() throws ObjectStreamException {
46         return new KeyedInstanceIdentifier<>(getTargetType(), getPathArguments(), isWildcarded(), getHash(), key);
47     }
48 }