Make NormalizedTuple generic 23/109323/1
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Dec 2023 01:06:48 +0000 (02:06 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Fri, 15 Dec 2023 01:06:48 +0000 (02:06 +0100)
NormalizedTuple should capture the type of NormalizedNode it carries.
This will be useful as we define more normalization APIs, where some
parts guarantee, for example, ContainerNode.

Change-Id: I01a3429c0bb38cd87d293dfbd154be7aa69c411d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedMountPoint.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedTuple.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/NormalizationResult.java
data/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/stream/ReusableStreamReceiver.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/NormalizationResultHolder.java
data/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/ReusableImmutableNormalizedNodeStreamWriter.java

index ffc3a67d312a07ee0d9e15c950c7f253c406e6a2..0b8a0e2cf12c631f0ec314e6e1a084a3848f012b 100644 (file)
@@ -15,7 +15,7 @@ import org.opendaylight.yangtools.yang.common.MountPointLabel;
  * corresponding {@link #context()}. Furthermore {@link #data()} is guaranteed to point at a {@link ContainerNode}.
  */
 @NonNullByDefault
-public interface NormalizedMountPoint extends NormalizedTuple {
+public interface NormalizedMountPoint extends NormalizedTuple<ContainerNode> {
     /**
      * Return the {@code mount-point} label.
      *
@@ -30,9 +30,6 @@ public interface NormalizedMountPoint extends NormalizedTuple {
      */
     MountPointContext context();
 
-    @Override
-    ContainerNode data();
-
     /*
      * FIXME: consider whether this interface should contain some information based on 'parent-reference':
      *        - List<YangXPathExpression.QualifiedBound> getParentReference()
index 3d1c96339f7edd1658ff223c1cdfa793a0f967b2..d04bc77ad2ec01327548ea28ade7fc6f0d97ecba 100644 (file)
@@ -22,13 +22,13 @@ import org.opendaylight.yangtools.concepts.Immutable;
 //        the corresponding metadata and/or mount points. Most notably mount points are only defined for ContainerNode
 //        and MapEntryNode.
 @Beta
-public interface NormalizedTuple extends Immutable {
+public interface NormalizedTuple<T extends NormalizedNode> extends Immutable {
     /**
      * Return the data portion of this tree.
      *
      * @return Data portion of this tree.
      */
-    @NonNull NormalizedNode data();
+    @NonNull T data();
 
     /**
      * Return the metadata portion of this tree. This portion is optional.
index 78a760c1cd145b5f934b5524d208f3c3f2de7b47..82d6875548fc7ca4c7012db666400c9aabd24951 100644 (file)
@@ -20,23 +20,23 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedTuple;
  * The result of a {@link NormalizedNodeStreamWriter} stream, i.e. of a normalization operation. It really is just an
  * implementation of {@link NormalizedTuple}.
  */
-public record NormalizationResult(
-        @NonNull NormalizedNode data,
+public record NormalizationResult<T extends NormalizedNode>(
+        @NonNull T data,
         @Nullable NormalizedMetadata metadata,
-        @Nullable NormalizedMountpoints mountPoints) implements NormalizedTuple {
+        @Nullable NormalizedMountpoints mountPoints) implements NormalizedTuple<T> {
     public NormalizationResult {
         requireNonNull(data);
     }
 
-    public NormalizationResult(final @NonNull NormalizedNode data) {
+    public NormalizationResult(final @NonNull T data) {
         this(data, null, null);
     }
 
-    public NormalizationResult(final @NonNull NormalizedNode data, final @Nullable NormalizedMetadata metadata) {
+    public NormalizationResult(final @NonNull T data, final @Nullable NormalizedMetadata metadata) {
         this(data, metadata, null);
     }
 
-    public NormalizationResult(final @NonNull NormalizedNode data, final @Nullable NormalizedMountpoints mountPoints) {
+    public NormalizationResult(final @NonNull T data, final @Nullable NormalizedMountpoints mountPoints) {
         this(data, null, mountPoints);
     }
 }
index cbef32e5ea8d2077f9d678692cbb3b5a14bcf178..9d47c116dbfe4ee7247d2dd6118a7f1677e7ac1f 100644 (file)
@@ -41,7 +41,7 @@ public interface ReusableStreamReceiver extends NormalizedNodeStreamWriter {
      *
      * @return Result of streaming, or {@code null} if not result is present.
      */
-    @Nullable NormalizationResult result();
+    @Nullable NormalizationResult<?> result();
 
     /**
      * Reset this writer to initial state.
index 71df459b86fe5df290c87a6c01c3f9a2d74a7c2b..f45aa1ec9109e023e25bc76070ee0793792793dd 100644 (file)
@@ -26,17 +26,17 @@ public final class NormalizationResultHolder implements Mutable {
     private NormalizedMetadata metadata;
     private NormalizedMountpoints mountPoints;
 
-    public @Nullable NormalizationResult result() {
+    public @Nullable NormalizationResult<?> result() {
         final var localData = data;
-        return localData == null ? null : new NormalizationResult(localData, metadata, mountPoints);
+        return localData == null ? null : new NormalizationResult<>(localData, metadata, mountPoints);
     }
 
-    public @NonNull NormalizationResult getResult() {
+    public @NonNull NormalizationResult<?> getResult() {
         final var localData = data;
         if (localData == null) {
             throw new IllegalStateException("Holder " + this + " has not been completed");
         }
-        return new NormalizationResult(localData, metadata, mountPoints);
+        return new NormalizationResult<>(localData, metadata, mountPoints);
     }
 
     void setData(final NormalizedNode data) {
index b45a9ae5e5df869867401ebe5f90d438c83b5a62..ba4f2725087f73fe1512ca0a05953e4db87aced6 100644 (file)
@@ -44,7 +44,7 @@ public final class ReusableImmutableNormalizedNodeStreamWriter extends Immutable
     }
 
     @Override
-    public NormalizationResult result() {
+    public NormalizationResult<?> result() {
         return builder.result();
     }