From: Robert Varga Date: Thu, 18 Mar 2021 08:18:01 +0000 (+0100) Subject: Remove EffectiveStatementState X-Git-Tag: v7.0.0~70 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=b58489321bc04d8c5ebca56bef8ecce3b4e964e2;p=yangtools.git Remove EffectiveStatementState This concept is used only by some orphan code, remove it along with the unused complexity. Change-Id: I496f67081360a4774d37f46ed8ee24fc99979265 Signed-off-by: Robert Varga --- 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 index fb8f763e9e..0000000000 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/EffectiveInstances.java +++ /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> 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 copies = new HashMap<>(4); - private final @NonNull E local; - - EffectiveInstances(final @NonNull E local) { - this.local = requireNonNull(local); - } - - @SuppressWarnings("unchecked") - static > @NonNull E local(final Object obj) { - return obj instanceof EffectiveInstances ? ((EffectiveInstances) 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> prevStmts = prev.effectiveSubstatements(); - final Collection> copyStmts = copy.effectiveSubstatements(); - if (prevStmts != copyStmts) { - if (prevStmts.size() != copyStmts.size()) { - LOG.trace("Key {} substatement count mismatch", key); - return copy; - } - - final Iterator> prevIt = prevStmts.iterator(); - final Iterator> 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; - } -} diff --git a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java index da7eacb947..da11198357 100644 --- a/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java +++ b/yang/yang-parser-reactor/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/reactor/ReactorStmtCtx.java @@ -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, 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, E extends Effec @Override public final > @NonNull Optional findSubstatementArgument( final @NonNull Class 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> 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, 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, 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: - *
    - *
  • {@code copy} and {@code this} statement share {@link #getOriginalCtx()} if it exists
  • - *
  • {@code copy} did not modify any statements relative to {@code this}
  • - *
- * - * - * @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 instances; - if (effective instanceof EffectiveInstances) { - instances = (EffectiveInstances) 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 index 301d8cd688..0000000000 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveSchemaTreeStatementState.java +++ /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 index d3d87edcc5..0000000000 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/EffectiveStatementState.java +++ /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. - * - *

- * {@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); - } -}