2 * Copyright (c) 2019 PANTHEON.tech, 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.data.api;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableList.Builder;
14 import java.io.Externalizable;
15 import java.io.IOException;
16 import java.io.ObjectInput;
17 import java.io.ObjectOutput;
18 import java.util.List;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 * Externalizable proxy for {@link YangInstanceIdentifier}.
24 final class YIDv1 implements Externalizable {
25 private static final long serialVersionUID = 1L;
27 private YangInstanceIdentifier yid;
29 @SuppressWarnings("checkstyle:redundantModifier")
34 YIDv1(final YangInstanceIdentifier yid) {
35 this.yid = requireNonNull(yid);
39 public void writeExternal(final ObjectOutput out) throws IOException {
40 final List<PathArgument> args = yid.getPathArguments();
41 out.writeInt(args.size());
42 for (PathArgument arg : args) {
43 // Unfortunately PathArgument is an interface and we do not have control over all its implementations,
44 // hence we did not bother with making them WritableObjects. This works reasonably well, though.
50 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
51 final int size = in.readInt();
52 final Builder<PathArgument> builder = ImmutableList.builderWithExpectedSize(size);
53 for (int i = 0; i < size; ++i) {
54 builder.add((PathArgument) in.readObject());
56 yid = YangInstanceIdentifier.create(builder.build());
59 private Object readResolve() {