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

org.opendaylight.yangtools.binding.DataObjectIdentifier 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;

import static java.util.Objects.requireNonNull;

import com.google.common.collect.ImmutableList;
import java.util.List;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.binding.impl.AbstractDataObjectIdentifierBuilder;
import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierBuilder;
import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierBuilderWithKey;
import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierImpl;
import org.opendaylight.yangtools.binding.impl.DataObjectIdentifierWithKey;

/**
 * A {@link DataObjectReference} matching at most one {@link DataObject}, consistent with YANG
 * {@code instance-identifier} addressing as captured by {@link BindingInstanceIdentifier}.
 *
 * @param  type of {@link DataObject} held in the last step.
 */
public sealed interface DataObjectIdentifier
        extends DataObjectReference, BindingInstanceIdentifier
        permits DataObjectIdentifier.WithKey, DataObjectIdentifierImpl {
    /**
     * A builder of {@link DataObjectReference} objects.
     *
     * @param  type of {@link DataObject} held in the last step.
     */
    sealed interface Builder extends DataObjectReference.Builder
            permits Builder.WithKey, AbstractDataObjectIdentifierBuilder {
        /**
         * A builder of {@link DataObjectReference.WithKey} objects.
         *
         * @param  type of {@link EntryObject} held in the last step.
         * @param  {@link Key} type
         */
        non-sealed interface WithKey, K extends Key>
                extends Builder, DataObjectReference.Builder.WithKey
                /* permits DataObjectReferenceBuilderWithKey, KeyedBuilder */ {
            @Override
            DataObjectIdentifier.WithKey build();
        }

        @Override
        > Builder augmentation(Class augmentation);

        @Override
        > Builder child(Class container);

        @Override
         & DataObject, N extends ChildOf> Builder child(
            Class caze, Class container);

        @Override
         & DataObject, K extends Key, N extends EntryObject & ChildOf>
            WithKey child(Class caze, Class listItem, K listKey);

        @Override
         & ChildOf, K extends Key> WithKey child(
            Class<@NonNull N> listItem, K listKey);

        @Override
        DataObjectIdentifier build();
    }

    /**
     * A {@link DataObjectIdentifier} pointing to an {@link EntryObject}.
     *
     * @param  Key type
     * @param  EntryObject type
     */
    sealed interface WithKey, K extends Key>
            extends DataObjectIdentifier, DataObjectReference.WithKey
            permits DataObjectIdentifierWithKey {
        @Override
        KeyStep lastStep();

        @Override
        DataObjectIdentifier.Builder.WithKey toBuilder();
    }

    static @NonNull DataObjectIdentifier ofUnsafeSteps(
            final Iterable> steps) {
        return ofUnsafeSteps(ImmutableList.copyOf(steps));
    }

    static @NonNull DataObjectIdentifier ofUnsafeSteps(
            final List> steps) {
        return ofUnsafeSteps(ImmutableList.copyOf(steps));
    }

    static @NonNull DataObjectIdentifier ofUnsafeSteps(
            final ImmutableList> steps) {
        return DataObjectIdentifierImpl.ofUnsafeSteps(steps);
    }

    static >> @NonNull Builder builder(
            final @NonNull Class container) {
        return new DataObjectIdentifierBuilder<>(DataObjectStep.of(container));
    }

    static > & DataObject, T extends ChildOf>
            @NonNull Builder builder(final @NonNull Class caze, final @NonNull Class container) {
        return new DataObjectIdentifierBuilder<>(DataObjectStep.of(caze, container));
    }

    static  & ChildOf>, K extends Key>
            Builder.@NonNull WithKey builder(final Class listItem, final K listKey) {
        return new DataObjectIdentifierBuilderWithKey<>(new KeyStep<>(listItem, listKey));
    }

    static > & DataObject,
            N extends EntryObject & ChildOf, K extends Key>
            Builder.@NonNull WithKey builder(final @NonNull Class caze, final @NonNull Class listItem,
                    final @NonNull K listKey) {
        return new DataObjectIdentifierBuilderWithKey<>(new KeyStep<>(listItem, requireNonNull(caze), listKey));
    }

    static , T extends ChildOf>
            @NonNull Builder builderOfInherited(final @NonNull Class root, final @NonNull Class container) {
        // FIXME: we are losing root identity, hence namespaces may not work correctly
        return new DataObjectIdentifierBuilder<>(DataObjectStep.of(container));
    }

    static , C extends ChoiceIn & DataObject, T extends ChildOf>
            @NonNull Builder builderOfInherited(final Class root,
                final Class caze, final Class container) {
        // FIXME: we are losing root identity, hence namespaces may not work correctly
        return new DataObjectIdentifierBuilder<>(DataObjectStep.of(caze, container));
    }

    static , N extends EntryObject & ChildOf, K extends Key>
            Builder.@NonNull WithKey builderOfInherited(final @NonNull Class root,
                final @NonNull Class listItem, final @NonNull K listKey) {
        // FIXME: we are losing root identity, hence namespaces may not work correctly
        return new DataObjectIdentifierBuilderWithKey<>(new KeyStep<>(listItem, listKey));
    }

    static , C extends ChoiceIn & DataObject,
            N extends EntryObject & ChildOf, K extends Key>
            Builder.@NonNull WithKey builderOfInherited(final Class root,
                final Class caze, final Class listItem, final K listKey) {
        // FIXME: we are losing root identity, hence namespaces may not work correctly
        return new DataObjectIdentifierBuilderWithKey<>(new KeyStep<>(listItem, requireNonNull(caze), listKey));
    }

    @Override
    Iterable> steps();

    @Override
    default boolean isExact() {
        return true;
    }

    @Override
    Builder toBuilder();

    @Override
    @Deprecated(since = "14.0.0")
    default boolean isWildcarded() {
        return false;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy