Enable binding-data-codec-dynamic build
[yangtools.git] / binding / binding-spec / src / main / java / org / opendaylight / yangtools / binding / InstanceIdentifierV3.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;
9
10 import com.google.common.collect.ImmutableList;
11 import java.io.Externalizable;
12 import java.io.IOException;
13 import java.io.NotSerializableException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.ObjectStreamException;
17 import java.io.Serial;
18 import org.eclipse.jdt.annotation.Nullable;
19
20 class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
21     @Serial
22     private static final long serialVersionUID = 3L;
23
24     private @Nullable Iterable<DataObjectStep<?>> pathArguments;
25     private @Nullable Class<T> targetType;
26     private boolean wildcarded;
27     private int hash;
28
29     @SuppressWarnings("redundantModifier")
30     public InstanceIdentifierV3() {
31         // For Externalizable
32     }
33
34     final int getHash() {
35         return hash;
36     }
37
38     final Iterable<DataObjectStep<?>> getPathArguments() {
39         return pathArguments;
40     }
41
42     final Class<T> getTargetType() {
43         return targetType;
44     }
45
46     final boolean isWildcarded() {
47         return wildcarded;
48     }
49
50     @Override
51     public void writeExternal(final ObjectOutput out) throws IOException {
52         throw new NotSerializableException(InstanceIdentifierV3.class.getName());
53     }
54
55     @Override
56     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
57         targetType = (Class<T>) in.readObject();
58         wildcarded = in.readBoolean();
59         hash = in.readInt();
60
61         final int size = in.readInt();
62         final var builder = ImmutableList.<DataObjectStep<?>>builderWithExpectedSize(size);
63         for (int i = 0; i < size; ++i) {
64             builder.add((DataObjectStep<?>) in.readObject());
65         }
66         pathArguments = builder.build();
67     }
68
69     @java.io.Serial
70     Object readResolve() throws ObjectStreamException {
71         return new InstanceIdentifier<>(targetType, pathArguments, wildcarded, hash);
72     }
73 }