/* * Copyright (c) 2022 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.mdsal.binding.api; import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import java.util.Objects; import org.eclipse.jdt.annotation.NonNull; import org.opendaylight.yangtools.concepts.Immutable; import org.opendaylight.yangtools.concepts.Mutable; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.ChoiceIn; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.DataRoot; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder; import org.opendaylight.yangtools.yang.binding.InstanceNotification; /** * A combination of an {@link InstanceNotification} class and its corresponding instantiation wildcard, expressed as * an {@link InstanceIdentifier}. This glue is required because instance notification interfaces are generated at the * place of their definition, most importantly in {@code grouping} and we actually need to bind to a particular * instantiation (e.g. a place where {@code uses} references that grouping). * * @param Generated InstanceNotification interface type * @param

Instance notification parent type */ @Beta public final class InstanceNotificationSpec, P extends DataObject> implements Immutable { private final @NonNull InstanceIdentifier

path; private final @NonNull Class type; private InstanceNotificationSpec(final Class type, final InstanceIdentifier

path) { this.type = requireNonNull(type); this.path = requireNonNull(path); } public static

> @NonNull Builder

builder(final Class

container) { return new Builder<>(InstanceIdentifier.builder(container)); } public static & DataObject, P extends ChildOf> @NonNull Builder

builder(final Class caze, final Class

container) { return new Builder<>(InstanceIdentifier.builder(caze, container)); } public @NonNull InstanceIdentifier

path() { return path; } public @NonNull Class type() { return type; } @Override public int hashCode() { return Objects.hash(type, path); } @Override public boolean equals(final Object obj) { if (obj == this) { return true; } if (!(obj instanceof InstanceNotificationSpec)) { return false; } final var other = (InstanceNotificationSpec) obj; return type.equals(other.type) && path.equals(other.path); } @Override public String toString() { return MoreObjects.toStringHelper(this).add("action", type).add("path", path).toString(); } @Beta public static final class Builder

implements Mutable { private final InstanceIdentifierBuilder

pathBuilder; Builder(final InstanceIdentifierBuilder

pathBuilder) { this.pathBuilder = requireNonNull(pathBuilder); } public > @NonNull Builder withPathChild(final Class container) { pathBuilder.child(container); return castThis(); } public & DataObject, N extends ChildOf> @NonNull Builder withPathChild(final Class caze, final Class container) { pathBuilder.child(caze, container); return castThis(); } public > @NonNull Builder withPathAugmentation( final Class container) { pathBuilder.augmentation(container); return castThis(); } public > @NonNull InstanceNotificationSpec build( final Class type) { return new InstanceNotificationSpec<>(type, pathBuilder.build()); } @SuppressWarnings("unchecked") private @NonNull Builder castThis() { return (Builder) this; } } }