/* * Copyright (c) 2021 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.Action; 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; /** * A combination of an {@link Action} class and its corresponding instantiation wildcard, expressed as * an {@link InstanceIdentifier}. This means that {@code list}s are treated exactly as @{code container}s are, e.g. * without a key value specification. * *
* This glue is required because action 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 Action interface type
* @param Action parent type
*/
@Beta
public final class ActionSpec, ?, ?>, P extends DataObject>
implements Immutable {
private final @NonNull InstanceIdentifier path;
private final @NonNull Class type;
private ActionSpec(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 builder(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 ActionSpec)) {
return false;
}
final var other = (ActionSpec, ?>) 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