import com.google.common.collect.ImmutableMap;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
-import java.util.Optional;
+import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.binding.Augmentable;
import org.opendaylight.yangtools.yang.binding.Augmentation;
import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
-import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* A base class for {@link DataObject}s which are also {@link Augmentable}, backed by {@link DataObjectCodecContext}.
@SuppressWarnings("unused")
private volatile ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> cachedAugmentations;
- protected AugmentableCodecDataObject(final DataObjectCodecContext<T, ?> context,
+ protected AugmentableCodecDataObject(final AbstractDataObjectCodecContext<T, ?> context,
final DistinctNodeContainer<?, ?> data) {
super(context, data);
}
public final <A extends Augmentation<T>> @Nullable A augmentation(final Class<A> augmentationType) {
requireNonNull(augmentationType, "Supplied augmentation must not be null.");
- final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> aug = acquireAugmentations();
+ final var aug = acquireAugmentations();
if (aug != null) {
return (A) aug.get(augmentationType);
}
@SuppressWarnings("rawtypes")
- final Optional<DataContainerCodecContext<?, ?>> optAugCtx = codecContext().possibleStreamChild(
- (Class) augmentationType);
+ final var optAugCtx = codecContext().possibleStreamChild((Class) augmentationType);
if (optAugCtx.isPresent()) {
- final DataContainerCodecContext<?, ?> augCtx = optAugCtx.orElseThrow();
+ final var augCtx = (AugmentationNodeContext<A>) optAugCtx.orElseThrow();
// Due to binding specification not representing grouping instantiations we can end up having the same
// augmentation applied to a grouping multiple times. While these augmentations have the same shape, they
// are still represented by distinct binding classes and therefore we need to make sure the result matches
// the augmentation the user is requesting -- otherwise a strict receiver would end up with a cryptic
// ClassCastException.
if (augmentationType.isAssignableFrom(augCtx.getBindingClass())) {
- final NormalizedNode augData = codecData().childByArg(augCtx.getDomPathArgument());
- if (augData != null) {
- return (A) augCtx.deserialize(augData);
+ final var augObj = augCtx.filterFrom((DataContainerNode) codecData());
+ if (augObj != null) {
+ return augObj;
}
}
}
}
@SuppressWarnings("unchecked")
- private ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> loadAugmentations() {
- final ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> ret = ImmutableMap.copyOf(
- codecContext().getAllAugmentationsFrom(codecData()));
+ private @NonNull ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>> loadAugmentations() {
+ final var ret = ImmutableMap.copyOf(codecContext().getAllAugmentationsFrom(codecData()));
final Object witness = CACHED_AUGMENTATIONS.compareAndExchangeRelease(this, null, ret);
return witness == null ? ret : (ImmutableMap<Class<? extends Augmentation<T>>, Augmentation<T>>) witness;
}