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

org.opendaylight.yangtools.binding.impl.DataObjectIdentifierImpl Maven / Gradle / Ivy

/*
 * Copyright (c) 2024 PANTHEON.tech, 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.binding.impl;

import static com.google.common.base.Verify.verify;

import com.google.common.collect.ImmutableList;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectStreamException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.binding.DataObject;
import org.opendaylight.yangtools.binding.DataObjectIdentifier;
import org.opendaylight.yangtools.binding.DataObjectStep;
import org.opendaylight.yangtools.binding.ExactDataObjectStep;
import org.opendaylight.yangtools.binding.KeyStep;

public sealed class DataObjectIdentifierImpl
        extends AbstractDataObjectReference> implements DataObjectIdentifier
        permits DataObjectIdentifierWithKey {
    @java.io.Serial
    private static final long serialVersionUID = 1L;

    DataObjectIdentifierImpl(final Iterable> steps) {
        super(steps);
    }

    public DataObjectIdentifierImpl(final Void unused, final Iterable> steps) {
        this(verifySteps(steps));
    }

    @SuppressWarnings("unchecked")
    private static @NonNull Iterable> verifySteps(
            final Iterable> steps) {
        steps.forEach(step -> verify(step instanceof ExactDataObjectStep, "%s is not an exact step", step));
        return (Iterable>) steps;
    }

    public static final @NonNull DataObjectIdentifierImpl ofUnsafeSteps(
            final ImmutableList> steps) {
        final var last = steps.getLast();
        return last instanceof KeyStep ? new DataObjectIdentifierWithKey<>(steps)
            : new DataObjectIdentifierImpl<>(steps);
    }

    @Override
    public AbstractDataObjectIdentifierBuilder toBuilder() {
        return new DataObjectIdentifierBuilder<>(this);
    }

    @Override
    public DataObjectIdentifierImpl toIdentifier() {
        return this;
    }

    @Override
    protected final Class contract() {
        return DataObjectIdentifier.class;
    }

    @java.io.Serial
    private void readObject(final ObjectInputStream stream) throws IOException, ClassNotFoundException {
        throwNSE();
    }

    @java.io.Serial
    private void readObjectNoData() throws ObjectStreamException {
        throwNSE();
    }

    @java.io.Serial
    private void writeObject(final ObjectOutputStream stream) throws IOException {
        throwNSE();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy