2 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.binding;
10 import com.google.common.collect.ImmutableList;
11 import com.google.common.collect.Iterables;
12 import java.io.Externalizable;
13 import java.io.IOException;
14 import java.io.ObjectInput;
15 import java.io.ObjectOutput;
16 import java.io.ObjectStreamException;
17 import java.io.Serial;
18 import java.util.ArrayList;
19 import java.util.List;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
23 class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
25 private static final long serialVersionUID = 3L;
27 private @Nullable Iterable<PathArgument> pathArguments;
28 private @Nullable Class<T> targetType;
29 private boolean wildcarded;
32 @SuppressWarnings("redundantModifier")
33 public InstanceIdentifierV3() {
37 InstanceIdentifierV3(final InstanceIdentifier<T> source) {
38 pathArguments = source.pathArguments;
39 targetType = source.getTargetType();
40 wildcarded = source.isWildcarded();
41 hash = source.hashCode();
48 final Iterable<PathArgument> getPathArguments() {
52 final Class<T> getTargetType() {
56 final boolean isWildcarded() {
61 public void writeExternal(final ObjectOutput out) throws IOException {
62 out.writeObject(targetType);
63 out.writeBoolean(wildcarded);
65 out.writeInt(Iterables.size(pathArguments));
66 for (Object o : pathArguments) {
72 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
73 targetType = (Class<T>) in.readObject();
74 wildcarded = in.readBoolean();
77 final int size = in.readInt();
78 final List<PathArgument> args = new ArrayList<>();
79 for (int i = 0; i < size; ++i) {
80 args.add((PathArgument) in.readObject());
82 pathArguments = ImmutableList.copyOf(args);
86 Object readResolve() throws ObjectStreamException {
87 return new InstanceIdentifier<>(targetType, pathArguments, wildcarded, hash);