All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opendaylight.yangtools.yang.binding.IIv5 Maven / Gradle / Ivy

/*
 * Copyright (c) 2018 Pantheon Technologies, s.r.o. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.yang.binding;

import com.google.common.collect.ImmutableList;
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.io.ObjectStreamException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.binding.DataObjectStep;

final class IIv5 implements Externalizable {
    @java.io.Serial
    private static final long serialVersionUID = 1L;

    private ImmutableList<@NonNull DataObjectStep> steps;

    @SuppressWarnings("redundantModifier")
    public IIv5() {
        // For Externalizable
    }

    IIv5(final InstanceIdentifier source) {
        steps = ImmutableList.copyOf(source.steps());
    }

    @Override
    public void writeExternal(final ObjectOutput out) throws IOException {
        out.writeInt(steps.size());
        for (var step : steps) {
            out.writeObject(step);
        }
    }

    @Override
    public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
        final int size = in.readInt();
        final var builder = ImmutableList.>builderWithExpectedSize(size);
        for (int i = 0; i < size; ++i) {
            builder.add((DataObjectStep) in.readObject());
        }
        steps = builder.build();
    }

    @java.io.Serial
    private Object readResolve() throws ObjectStreamException {
        return InstanceIdentifier.unsafeOf(steps);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy