Modernize AbstractDataObjectModification 04/106604/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 16:50:29 +0000 (18:50 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 21 Jun 2023 16:51:05 +0000 (18:51 +0200)
We are using deprecated methods here. Migrating to their replacement
makes for a more fluent codebase.

Change-Id: Ic0a1f1653f13d0bb12ec97f2ef5bd2d6d4e388e3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/AbstractDataObjectModification.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyAugmentationModification.java
binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java

index bd9a555f3e186a5c9466613c886fd6202e79f113..73e44d1788f6881c414cb5569da10520f3b38b49 100644 (file)
@@ -21,7 +21,6 @@ import java.lang.invoke.VarHandle;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNull;
@@ -150,7 +149,7 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
     }
 
     private @Nullable T loadDataBefore() {
-        final var computed = deserialize(domData.getDataBefore());
+        final var computed = deserializeNullable(domData.dataBefore());
         final var witness = DATA_BEFORE.compareAndExchangeRelease(this, null, mask(computed));
         return witness == null ? computed : unmask(witness);
     }
@@ -162,7 +161,7 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
     }
 
     private @Nullable T loadDataAfter() {
-        final var computed = deserialize(domData.getDataAfter());
+        final var computed = deserializeNullable(domData.dataAfter());
         final var witness = DATA_AFTER.compareAndExchangeRelease(this, null, mask(computed));
         return witness == null ? computed : unmask(witness);
     }
@@ -176,8 +175,8 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
         return obj == NULL_DATA_OBJECT ? null : (T) verifyNotNull(obj);
     }
 
-    private @Nullable T deserialize(final Optional<NormalizedNode> normalized) {
-        return normalized.isEmpty() ? null : deserialize(normalized.orElseThrow());
+    private @Nullable T deserializeNullable(final @Nullable NormalizedNode normalized) {
+        return normalized == null ? null : deserialize(normalized);
     }
 
     abstract @Nullable T deserialize(@NonNull NormalizedNode normalized);
@@ -192,10 +191,10 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
         var current = toEnter.hasNext() ? firstModifiedChild(toEnter.next()) : domData;
         // ... and for everything else we can just go wild
         while (toEnter.hasNext() && current != null) {
-            current = current.getModifiedChild(toEnter.next()).orElse(null);
+            current = current.modifiedChild(toEnter.next());
         }
 
-        if (current == null || current.getModificationType() == UNMODIFIED) {
+        if (current == null || current.modificationType() == UNMODIFIED) {
             return null;
         }
         return from(childCodec, current);
@@ -322,8 +321,8 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
         final var augmentChildren =
             ArrayListMultimap.<BindingAugmentationCodecTreeNode<?>, DataTreeCandidateNode>create();
 
-        for (var domChildNode : parent.getChildNodes()) {
-            if (domChildNode.getModificationType() != UNMODIFIED) {
+        for (var domChildNode : parent.childNodes()) {
+            if (domChildNode.modificationType() != UNMODIFIED) {
                 final var type = BindingStructuralType.from(domChildNode);
                 if (type != BindingStructuralType.NOT_ADDRESSABLE) {
                     /*
@@ -331,7 +330,7 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
                      * We will use that type to further specify debug log.
                      */
                     try {
-                        final var childCodec = parentCodec.yangPathArgumentChild(domChildNode.getIdentifier());
+                        final var childCodec = parentCodec.yangPathArgumentChild(domChildNode.name());
                         if (childCodec instanceof BindingDataObjectCodecTreeNode<?> childDataObjectCodec) {
                             populateList(result, type, childDataObjectCodec, domChildNode);
                         } else if (childCodec instanceof BindingAugmentationCodecTreeNode<?> childAugmentationCodec) {
@@ -366,10 +365,10 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
         switch (type) {
             case INVISIBLE_LIST:
                 // We use parent codec intentionally.
-                populateListWithSingleCodec(result, childCodec, domChildNode.getChildNodes());
+                populateListWithSingleCodec(result, childCodec, domChildNode.childNodes());
                 break;
             case INVISIBLE_CONTAINER:
-                populateList(result, childCodec, domChildNode, domChildNode.getChildNodes());
+                populateList(result, childCodec, domChildNode, domChildNode.childNodes());
                 break;
             case UNKNOWN:
             case VISIBLE_CONTAINER:
@@ -383,7 +382,7 @@ abstract sealed class AbstractDataObjectModification<T extends DataObject, N ext
             final ImmutableList.Builder<AbstractDataObjectModification<?, ?>> result,
             final BindingDataObjectCodecTreeNode<?> codec, final Collection<DataTreeCandidateNode> childNodes) {
         for (var child : childNodes) {
-            if (child.getModificationType() != UNMODIFIED) {
+            if (child.modificationType() != UNMODIFIED) {
                 result.add(new LazyDataObjectModification<>(codec, child));
             }
         }
index 9b1d1e4ecc0624f20c9a19dc65d508f878ac7384..8a2594468dcb569d9bd1b2bf6a16426c486ceaa4 100644 (file)
@@ -40,7 +40,7 @@ final class LazyAugmentationModification<A extends Augmentation<?>>
             final Collection<DataTreeCandidateNode> children) {
         // Filter out any unmodified children first
         final var domChildren = children.stream()
-            .filter(childMod -> childMod.getModificationType() != UNMODIFIED)
+            .filter(childMod -> childMod.modificationType() != UNMODIFIED)
             .collect(ImmutableList.toImmutableList());
         // Only return a modification if there is something left
         return domChildren.isEmpty() ? null : new LazyAugmentationModification<>(codec, parent, domChildren);
@@ -50,7 +50,10 @@ final class LazyAugmentationModification<A extends Augmentation<?>>
             final BindingAugmentationCodecTreeNode<A> codec, final DataTreeCandidateNode parent) {
         final var builder = ImmutableList.<DataTreeCandidateNode>builder();
         for (var pathArg : codec.childPathArguments()) {
-            parent.getModifiedChild(pathArg).ifPresent(builder::add);
+            final var child = parent.modifiedChild(pathArg);
+            if (child != null) {
+                builder.add(child);
+            }
         }
         final var domChildren = builder.build();
         return domChildren.isEmpty() ? null : new LazyAugmentationModification<>(codec, parent, domChildren);
@@ -83,7 +86,7 @@ final class LazyAugmentationModification<A extends Augmentation<?>>
     DataTreeCandidateNode firstModifiedChild(final PathArgument arg) {
         // Not entirely efficient linear search, but otherwise we'd have to index, which is even slower
         return domChildNodes.stream()
-            .filter(child -> arg.equals(child.getIdentifier()))
+            .filter(child -> arg.equals(child.name()))
             .findFirst()
             .orElse(null);
     }
@@ -91,7 +94,7 @@ final class LazyAugmentationModification<A extends Augmentation<?>>
     @Override
     ToStringHelper addToStringAttributes(final ToStringHelper helper) {
         return super.addToStringAttributes(helper)
-            .add("domType", domData.getModificationType())
+            .add("domType", domData.modificationType())
             .add("domChildren", domChildNodes);
     }
 }
index b030e0ede33fabc67e10da2228449b9e1caf104a..d885f30c49d35b40c400d5e12ea49184473a3da0 100644 (file)
@@ -28,17 +28,17 @@ import org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidateNode;
 final class LazyDataObjectModification<T extends DataObject>
         extends AbstractDataObjectModification<T, BindingDataObjectCodecTreeNode<T>> {
     LazyDataObjectModification(final BindingDataObjectCodecTreeNode<T> codec, final DataTreeCandidateNode domData) {
-        super(domData, codec, codec.deserializePathArgument(domData.getIdentifier()));
+        super(domData, codec, codec.deserializePathArgument(domData.name()));
     }
 
     @Override
     Collection<DataTreeCandidateNode> domChildNodes() {
-        return domData.getChildNodes();
+        return domData.childNodes();
     }
 
     @Override
     org.opendaylight.yangtools.yang.data.tree.api.ModificationType domModificationType() {
-        return domData.getModificationType();
+        return domData.modificationType();
     }
 
     @Override
@@ -48,7 +48,7 @@ final class LazyDataObjectModification<T extends DataObject>
 
     @Override
     DataTreeCandidateNode firstModifiedChild(final PathArgument arg) {
-        return domData.getModifiedChild(arg).orElse(null);
+        return domData.modifiedChild(arg);
     }
 
     @Override