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.util.ArrayList;
18 import java.util.List;
19 import org.eclipse.jdt.annotation.Nullable;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
22 class InstanceIdentifierV3<T extends DataObject> implements Externalizable {
23 private static final long serialVersionUID = 3L;
25 private @Nullable Iterable<PathArgument> pathArguments;
26 private @Nullable Class<T> targetType;
27 private boolean wildcarded;
30 @SuppressWarnings("redundantModifier")
31 public InstanceIdentifierV3() {
35 InstanceIdentifierV3(final InstanceIdentifier<T> source) {
36 pathArguments = source.pathArguments;
37 targetType = source.getTargetType();
38 wildcarded = source.isWildcarded();
39 hash = source.hashCode();
46 final Iterable<PathArgument> getPathArguments() {
50 final Class<T> getTargetType() {
54 final boolean isWildcarded() {
59 public void writeExternal(final ObjectOutput out) throws IOException {
60 out.writeObject(targetType);
61 out.writeBoolean(wildcarded);
63 out.writeInt(Iterables.size(pathArguments));
64 for (Object o : pathArguments) {
70 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
71 targetType = (Class<T>) in.readObject();
72 wildcarded = in.readBoolean();
75 final int size = in.readInt();
76 final List<PathArgument> args = new ArrayList<>();
77 for (int i = 0; i < size; ++i) {
78 args.add((PathArgument) in.readObject());
80 pathArguments = ImmutableList.copyOf(args);
83 Object readResolve() throws ObjectStreamException {
84 return new InstanceIdentifier<>(targetType, pathArguments, wildcarded, hash);