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 super C>> Builder child(
Class caze, Class container);
@Override
& DataObject, K extends Key, N extends EntryObject & ChildOf super C>>
WithKey child(Class caze, Class listItem, K listKey);
@Override
& ChildOf super T>, 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 extends @NonNull ExactDataObjectStep>> steps) {
return ofUnsafeSteps(ImmutableList.copyOf(steps));
}
static @NonNull DataObjectIdentifier> ofUnsafeSteps(
final List extends @NonNull ExactDataObjectStep>> steps) {
return ofUnsafeSteps(ImmutableList.copyOf(steps));
}
static @NonNull DataObjectIdentifier> ofUnsafeSteps(
final ImmutableList extends @NonNull ExactDataObjectStep>> steps) {
return DataObjectIdentifierImpl.ofUnsafeSteps(steps);
}
static >> @NonNull Builder builder(
final @NonNull Class container) {
return new DataObjectIdentifierBuilder<>(DataObjectStep.of(container));
}
static > & DataObject, T extends ChildOf super C>>
@NonNull Builder builder(final @NonNull Class caze, final @NonNull Class container) {
return new DataObjectIdentifierBuilder<>(DataObjectStep.of(caze, container));
}
static & ChildOf extends DataRoot>>, 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 super C>, 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 super R>>
@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 super R> & DataObject, T extends ChildOf super C>>
@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 super R>, 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 super R> & DataObject,
N extends EntryObject & ChildOf super C>, 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 extends @NonNull ExactDataObjectStep>> steps();
@Override
default boolean isExact() {
return true;
}
@Override
Builder toBuilder();
@Override
@Deprecated(since = "14.0.0")
default boolean isWildcarded() {
return false;
}
}