Remove EffectiveStatementState 19/95519/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Mar 2021 08:18:01 +0000 (09:18 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 18 Mar 2021 08:32:38 +0000 (09:32 +0100)
This concept is used only by some orphan code, remove it along with
the unused complexity.

Change-Id: I496f67081360a4774d37f46ed8ee24fc99979265
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/EffectiveInstances.java [deleted file]
yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveSchemaTreeStatementState.java [deleted file]
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStatementState.java [deleted file]

diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/EffectiveInstances.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/EffectiveInstances.java
deleted file mode 100644 (file)
index fb8f763..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.yangtools.yang.parser.stmt.reactor;
-
-import static java.util.Objects.requireNonNull;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Mutable;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Statement-reuse expansion of a single instance. The idea here is that a statement can end up being replicated the
- * same way multiple times -- which does not typically happen, but when it does it is worth exploiting.
- *
- * @param E {@link EffectiveStatement} type
- */
-final class EffectiveInstances<E extends EffectiveStatement<?, ?>> implements Mutable {
-    private static final Logger LOG = LoggerFactory.getLogger(EffectiveInstances.class);
-
-    // Note on sizing: this fits three entries without expansion. Note we do not include the local copy, as it does
-    // not have the same original.
-    private final Map<EffectiveStatementState, E> copies = new HashMap<>(4);
-    private final @NonNull E local;
-
-    EffectiveInstances(final @NonNull E local) {
-        this.local = requireNonNull(local);
-    }
-
-    @SuppressWarnings("unchecked")
-    static <E extends EffectiveStatement<?, ?>> @NonNull E local(final Object obj) {
-        return obj instanceof EffectiveInstances ? ((EffectiveInstances<E>) obj).local : requireNonNull((E) obj);
-    }
-
-    @NonNull E attachCopy(final @NonNull EffectiveStatementState key, @NonNull final E copy) {
-        final E prev = copies.putIfAbsent(requireNonNull(key), requireNonNull(copy));
-        if (prev == null) {
-            // Nothing matching state
-            return copy;
-        }
-
-        // We need to make sure substatements are actually the same. If they are not, we'll just return the copy,
-        // playing it safe.
-        final Collection<? extends EffectiveStatement<?, ?>> prevStmts = prev.effectiveSubstatements();
-        final Collection<? extends EffectiveStatement<?, ?>> copyStmts = copy.effectiveSubstatements();
-        if (prevStmts != copyStmts) {
-            if (prevStmts.size() != copyStmts.size()) {
-                LOG.trace("Key {} substatement count mismatch", key);
-                return copy;
-            }
-
-            final Iterator<? extends EffectiveStatement<?, ?>> prevIt = prevStmts.iterator();
-            final Iterator<? extends EffectiveStatement<?, ?>> copyIt = copyStmts.iterator();
-            while (prevIt.hasNext()) {
-                if (prevIt.next() != copyIt.next()) {
-                    LOG.trace("Key {} substatement mismatch", key);
-                    return copy;
-                }
-            }
-        }
-
-        LOG.trace("Key {} substatement reused", key);
-        return prev;
-    }
-}
index da7eacb947442045dd4ca4e7b8b93ee573901fef..da11198357174a1a0bda4652904feeafdd4babb5 100644 (file)
@@ -9,7 +9,6 @@ package org.opendaylight.yangtools.yang.parser.stmt.reactor;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Verify.verify;
-import static com.google.common.base.Verify.verifyNotNull;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
@@ -35,7 +34,6 @@ import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
 import org.opendaylight.yangtools.yang.model.api.stmt.UsesStatement;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
 import org.opendaylight.yangtools.yang.parser.spi.meta.CopyType;
-import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStatementState;
 import org.opendaylight.yangtools.yang.parser.spi.meta.EffectiveStmtCtx.Current;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
@@ -120,7 +118,7 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
      * {@link #buildEffective()} instance. If this context is reused, it can be inflated to {@link EffectiveInstances}
      * and also act as a common instance reuse site.
      */
-    private @Nullable Object effectiveInstance;
+    private @Nullable E effectiveInstance;
 
     // Master flag controlling whether this context can yield an effective statement
     // FIXME: investigate the mechanics that are being supported by this, as it would be beneficial if we can get rid
@@ -265,16 +263,15 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
     @Override
     public final <X, Z extends EffectiveStatement<X, ?>> @NonNull Optional<X> findSubstatementArgument(
             final @NonNull Class<Z> type) {
-        final Object existing = effectiveInstance;
-        return existing != null ? EffectiveInstances.local(existing).findFirstEffectiveSubstatementArgument(type)
+        final E existing = effectiveInstance;
+        return existing != null ? existing.findFirstEffectiveSubstatementArgument(type)
             : findSubstatementArgumentImpl(type);
     }
 
     @Override
     public final boolean hasSubstatement(final @NonNull Class<? extends EffectiveStatement<?, ?>> type) {
-        final Object existing = effectiveInstance;
-        return existing != null ? EffectiveInstances.local(existing).findFirstEffectiveSubstatement(type).isPresent()
-            : hasSubstatementImpl(type);
+        final E existing = effectiveInstance;
+        return existing != null ? existing.findFirstEffectiveSubstatement(type).isPresent() : hasSubstatementImpl(type);
     }
 
     // Visible due to InferredStatementContext's override. At this point we do not have an effective instance available.
@@ -381,8 +378,8 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
 
     @Override
     public final E buildEffective() {
-        final Object existing;
-        return (existing = effectiveInstance) != null ? EffectiveInstances.local(existing) : loadEffective();
+        final E existing;
+        return (existing = effectiveInstance) != null ? existing : loadEffective();
     }
 
     private @NonNull E loadEffective() {
@@ -404,31 +401,6 @@ abstract class ReactorStmtCtx<A, D extends DeclaredStatement<A>, E extends Effec
 
     abstract @NonNull E createEffective();
 
-
-    /**
-     * Attach an effective copy of this statement. This essentially acts as a map, where we make a few assumptions:
-     * <ul>
-     *   <li>{@code copy} and {@code this} statement share {@link #getOriginalCtx()} if it exists</li>
-     *   <li>{@code copy} did not modify any statements relative to {@code this}</li>
-     * </ul>
-     *
-     *
-     * @param state effective statement state, acting as a lookup key
-     * @param copy New copy to append
-     * @return {@code copy} or a previously-created instances with the same {@code state}
-     */
-    @SuppressWarnings("unchecked")
-    final @NonNull E attachCopy(final @NonNull EffectiveStatementState state, final @NonNull E copy) {
-        final Object effective = verifyNotNull(effectiveInstance, "Attaching copy to a unbuilt %s", this);
-        final EffectiveInstances<E> instances;
-        if (effective instanceof EffectiveInstances) {
-            instances = (EffectiveInstances<E>) effective;
-        } else {
-            effectiveInstance = instances = new EffectiveInstances<>((E) effective);
-        }
-        return instances.attachCopy(state, copy);
-    }
-
     /**
      * Walk this statement's copy history and return the statement closest to original which has not had its effective
      * statements modified. This statement and returned substatement logically have the same set of substatements, hence
diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveSchemaTreeStatementState.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveSchemaTreeStatementState.java
deleted file mode 100644 (file)
index 301d8cd..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.yangtools.yang.parser.spi.meta;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Immutable;
-
-@Beta
-public final class EffectiveSchemaTreeStatementState extends EffectiveStatementState {
-    private final int flags;
-
-    public EffectiveSchemaTreeStatementState(final @NonNull Immutable identity, final int flags) {
-        super(identity);
-        this.flags = flags;
-    }
-
-    @Override
-    public int hashCode() {
-        return identity().hashCode() * 31 + Integer.hashCode(flags);
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof EffectiveSchemaTreeStatementState)) {
-            return false;
-        }
-        final EffectiveSchemaTreeStatementState other = (EffectiveSchemaTreeStatementState) obj;
-        return flags == other.flags && identity().equals(other.identity());
-    }
-
-    @Override
-    protected ToStringHelper addToStringAttributes(final ToStringHelper helper) {
-        return super.addToStringAttributes(helper).add("flags", flags);
-    }
-}
\ No newline at end of file
diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStatementState.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStatementState.java
deleted file mode 100644 (file)
index d3d87ed..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.yangtools.yang.parser.spi.meta;
-
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.annotations.Beta;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.MoreObjects.ToStringHelper;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
-
-/**
- * Effective summary of a {@link EffectiveStatement}'s implementation state. This class serves as a shared concept
- * between {@link StatementFactory} and common reactor, driving statement reuse.
- *
- * <p>
- * {@link StatementFactory} implementations are expected to subclass {@link EffectiveStatementState}, adding whatever
- * additional state is needed and implement {@link #hashCode()} and {@link #equals(Object)} accordingly.
- */
-@Beta
-public abstract class EffectiveStatementState implements Immutable {
-    private final @NonNull Immutable identity;
-
-    protected EffectiveStatementState(final @NonNull Immutable identity) {
-        this.identity = requireNonNull(identity);
-    }
-
-    protected final @NonNull Immutable identity() {
-        return identity;
-    }
-
-    @Override
-    public abstract int hashCode();
-
-    @Override
-    public abstract boolean equals(Object obj);
-
-    @Override
-    public final String toString() {
-        return addToStringAttributes(MoreObjects.toStringHelper(this)).toString();
-    }
-
-    protected @NonNull ToStringHelper addToStringAttributes(final @NonNull ToStringHelper helper) {
-        return helper.add("identity", identity);
-    }
-}