Tighten canReuseCurrent() contract 31/105331/2
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 8 Apr 2023 19:40:26 +0000 (21:40 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 8 Apr 2023 19:45:05 +0000 (21:45 +0200)
The we are passing a List down and that is what substatement semantics
are: adjust the method signature to use List instead of Collection.

Change-Id: Iefa694657b4540f73452f9d492744dac5da25d14
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractSchemaTreeStatementSupport.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementFactory.java
parser/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StatementSupport.java

index 4293862a69f3b882e509be7b3b3988df87c96025..2fb22889c9ab41fd56d0e7bcda2cef93a14c295b 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
 import com.google.common.annotations.Beta;
-import java.util.Collection;
+import java.util.List;
 import org.eclipse.jdt.annotation.Nullable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.CopyableNode;
@@ -36,7 +36,7 @@ public abstract class AbstractSchemaTreeStatementSupport<D extends DeclaredState
         private static final class Instantiated<D extends DeclaredStatement<QName>> extends SchemaTreeEquality<D> {
             @Override
             public boolean canReuseCurrent(final Current<QName, D> copy, final Current<QName, D> current,
-                    final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+                    final List<? extends EffectiveStatement<?, ?>> substatements) {
                 return copy.effectiveConfig() == current.effectiveConfig()
                     && super.canReuseCurrent(copy, current, substatements);
             }
@@ -44,7 +44,7 @@ public abstract class AbstractSchemaTreeStatementSupport<D extends DeclaredState
 
         @Override
         public boolean canReuseCurrent(final Current<QName, D> copy, final Current<QName, D> current,
-                final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+                final List<? extends EffectiveStatement<?, ?>> substatements) {
             return equalHistory(copy.history(), current.history())
                 && copy.getArgument().equals(current.getArgument());
         }
index 93976f548189560c521be2a1be41d14cf3d75939..d0d25805e36cc0b5c574aae03c0cd991d66a987f 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.parser.spi.meta;
 
-import java.util.Collection;
+import java.util.List;
 import java.util.stream.Stream;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -69,7 +69,7 @@ public interface StatementFactory<A, D extends DeclaredStatement<A>, E extends E
      * @throws NullPointerException if any argument is null
      */
     boolean canReuseCurrent(@NonNull Current<A, D> copy, @NonNull Current<A, D> current,
-        @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
+        @NonNull List<? extends EffectiveStatement<?, ?>> substatements);
 
     /**
      * Return the {@link EffectiveStatementState} for a particular statement. This acts as a summary for comparison with
index 633528ea345ae68a7a463cb7b1e340208b308d61..6a4a4f2e3bdd1697847b6f7f54979fef7c714419 100644 (file)
@@ -12,7 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.VerifyException;
-import java.util.Collection;
+import java.util.List;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jdt.annotation.Nullable;
@@ -41,7 +41,7 @@ import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E extends EffectiveStatement<A, D>>
         implements StatementFactory<A, D, E> {
     /**
-     * A baseline class for implementing the {@link StatementFactory#canReuseCurrent(Current, Current, Collection)}
+     * A baseline class for implementing the {@link StatementFactory#canReuseCurrent(Current, Current, List)}
      * contract in a manner which is consistent with a statement's {@link CopyPolicy}.
      *
      * @param <A> Argument type
@@ -129,7 +129,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
         }
 
         abstract boolean canReuseCurrent(@NonNull Current<A, D> copy, @NonNull Current<A, D> current,
-            @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
+            @NonNull List<? extends EffectiveStatement<?, ?>> substatements);
 
         private static final class AlwaysFail<A, D extends DeclaredStatement<A>> extends StatementPolicy<A, D> {
             static final @NonNull AlwaysFail<?, ?> IGNORE = new AlwaysFail<>(CopyPolicy.IGNORE);
@@ -141,7 +141,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
 
             @Override
             boolean canReuseCurrent(final Current<A, D> copy, final Current<A, D> current,
-                    final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+                    final List<? extends EffectiveStatement<?, ?>> substatements) {
                 throw new VerifyException("This implementation should never be invoked");
             }
         }
@@ -167,7 +167,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
 
             @Override
             boolean canReuseCurrent(final Current<A, D> copy, final Current<A, D> current,
-                    final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+                    final List<? extends EffectiveStatement<?, ?>> substatements) {
                 return equality.canReuseCurrent(copy, current, substatements);
             }
         }
@@ -184,7 +184,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
     public interface StatementEquality<A, D extends DeclaredStatement<A>> {
         /**
          * Determine whether {@code current} statement has the same semantics as the provided copy. See the contract
-         * specification of {@link StatementFactory#canReuseCurrent(Current, Current, Collection)}.
+         * specification of {@link StatementFactory#canReuseCurrent(Current, Current, List)}.
          *
          * @param copy Copy of current effective context
          * @param current Current effective context
@@ -192,7 +192,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
          * @return True if {@code current} can be reused in place of {@code copy}, false if the copy needs to be used.
          */
         boolean canReuseCurrent(@NonNull Current<A, D> copy, @NonNull Current<A, D> current,
-            @NonNull Collection<? extends EffectiveStatement<?, ?>> substatements);
+            @NonNull List<? extends EffectiveStatement<?, ?>> substatements);
     }
 
     /**
@@ -213,16 +213,16 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
     @Beta
     protected StatementSupport(final StatementSupport<A, D, E> delegate) {
         checkArgument(delegate != this);
-        this.publicDefinition = delegate.publicDefinition;
-        this.policy = delegate.policy;
-        this.copyPolicy = delegate.copyPolicy;
+        publicDefinition = delegate.publicDefinition;
+        policy = delegate.policy;
+        copyPolicy = delegate.copyPolicy;
     }
 
     @Beta
     protected StatementSupport(final StatementDefinition publicDefinition, final StatementPolicy<A, D> policy) {
         this.publicDefinition = requireNonNull(publicDefinition);
         this.policy = requireNonNull(policy);
-        this.copyPolicy = policy.copyPolicy;
+        copyPolicy = policy.copyPolicy;
     }
 
     /**
@@ -283,7 +283,7 @@ public abstract class StatementSupport<A, D extends DeclaredStatement<A>, E exte
 
     @Override
     public final boolean canReuseCurrent(final Current<A, D> copy, final Current<A, D> current,
-            final Collection<? extends EffectiveStatement<?, ?>> substatements) {
+            final List<? extends EffectiveStatement<?, ?>> substatements) {
         return policy.canReuseCurrent(copy, current, substatements);
     }