Remove model.api.SchemaPath 51/97351/10
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 28 Aug 2021 01:41:27 +0000 (03:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 10 Aug 2022 14:29:09 +0000 (16:29 +0200)
SchemaPath is of no further use to us. Purge it with fire.

JIRA: YANGTOOLS-1236
Change-Id: Ib66523e2393f526d64c111684f7bb308fdb6512c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/PathFromRoot.java [deleted file]
model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java [deleted file]

diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/PathFromRoot.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/PathFromRoot.java
deleted file mode 100644 (file)
index 7b70b17..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright (c) 2020 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.model.api;
-
-import static java.util.Objects.requireNonNull;
-
-import java.lang.invoke.MethodHandles;
-import java.lang.invoke.VarHandle;
-import java.util.AbstractList;
-import java.util.ArrayDeque;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.Iterator;
-import java.util.Spliterator;
-import org.eclipse.jdt.annotation.NonNull;
-import org.eclipse.jdt.annotation.Nullable;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-
-@Deprecated(since = "7.0.9", forRemoval = true)
-final class PathFromRoot extends AbstractList<QName> implements Immutable {
-    private static final QName[] EMPTY_QNAMES = new QName[0];
-    private static final VarHandle QNAMES;
-
-    static {
-        try {
-            QNAMES = MethodHandles.lookup().findVarHandle(PathFromRoot.class, "qnames", QName[].class);
-        } catch (NoSuchFieldException | IllegalAccessException e) {
-            throw new ExceptionInInitializerError(e);
-        }
-    }
-
-    private final SchemaPath path;
-
-    @SuppressWarnings("unused")
-    private QName @Nullable [] qnames;
-
-    PathFromRoot(final SchemaPath path) {
-        this.path = requireNonNull(path);
-    }
-
-    @Override
-    public Iterator<QName> iterator() {
-        return Arrays.asList(qnames()).iterator();
-    }
-
-    @Override
-    public Spliterator<QName> spliterator() {
-        return Arrays.spliterator(qnames());
-    }
-
-    @Override
-    public QName get(final int index) {
-        return qnames()[index];
-    }
-
-    @Override
-    public boolean isEmpty() {
-        return false;
-    }
-
-    @Override
-    public int size() {
-        return qnames().length;
-    }
-
-    private QName @NonNull [] qnames() {
-        final QName[] local = (QName[]) QNAMES.getAcquire(this);
-        return local != null ? local : loadQNames();
-    }
-
-    private QName @NonNull [] loadQNames() {
-        final Deque<QName> tmp = new ArrayDeque<>();
-        for (QName qname : path.getPathTowardsRoot()) {
-            tmp.addFirst(qname);
-        }
-
-        final QName[] result = tmp.toArray(EMPTY_QNAMES);
-        // We do not care about atomicity here
-        QNAMES.setRelease(this, result);
-        return result;
-    }
-}
diff --git a/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java b/model/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaPath.java
deleted file mode 100644 (file)
index 5096b28..0000000
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * Copyright (c) 2013 Cisco Systems, Inc. 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.model.api;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkState;
-import static java.util.Objects.requireNonNull;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.UnmodifiableIterator;
-import java.util.Arrays;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Objects;
-import org.eclipse.jdt.annotation.NonNull;
-import org.opendaylight.yangtools.concepts.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
-import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
-
-/**
- * Represents unique path to the every node inside the module.
- *
- * @deprecated This path is not really unique, as it does not handle YANG namespace overlap correctly. There are two
- *             different replacements for this class:
- *             <ul>
- *               <li>{@link SchemaNodeIdentifier} for use in
- *                   <a href="https://datatracker.ietf.org/doc/html/rfc7950#section-6.5">YANG schema addressing</a>
- *                   contexts</li>
- *               <li>{@link EffectiveStatementInference} for use in contexts where the intent is to exchange pointer
- *                   to a specific statement. Unlike SchemaPath, though, it does not require additional lookup in most
- *                   cases</li>
- *             </ul>
- *             This class is scheduled for removal in the next major release.
- */
-@Deprecated(since = "7.0.8", forRemoval = true)
-public abstract class SchemaPath implements Immutable {
-
-    /**
-     * An absolute SchemaPath.
-     */
-    private static final class AbsoluteSchemaPath extends SchemaPath {
-        private AbsoluteSchemaPath(final SchemaPath parent, final QName qname) {
-            super(parent, qname);
-        }
-
-        @Override
-        public boolean isAbsolute() {
-            return true;
-        }
-
-        @Override
-        public AbsoluteSchemaPath createChild(final QName element) {
-            return new AbsoluteSchemaPath(this, requireNonNull(element));
-        }
-    }
-
-    /**
-     * A relative SchemaPath.
-     */
-    private static final class RelativeSchemaPath extends SchemaPath {
-        private RelativeSchemaPath(final SchemaPath parent, final QName qname) {
-            super(parent, qname);
-        }
-
-        @Override
-        public boolean isAbsolute() {
-            return false;
-        }
-
-        @Override
-        public RelativeSchemaPath createChild(final QName element) {
-            return new RelativeSchemaPath(this, requireNonNull(element));
-        }
-    }
-
-    /**
-     * Shared instance of the conceptual root schema node.
-     */
-    public static final @NonNull SchemaPath ROOT = new AbsoluteSchemaPath(null, null);
-
-    /**
-     * Shared instance of the "same" relative schema node.
-     */
-    public static final @NonNull SchemaPath SAME = new RelativeSchemaPath(null, null);
-
-    /**
-     * Parent path.
-     */
-    private final SchemaPath parent;
-
-    /**
-     * This component.
-     */
-    private final QName qname;
-
-    /**
-     * Cached hash code. We can use this since we are immutable.
-     */
-    private final int hash;
-
-    SchemaPath(final SchemaPath parent, final QName qname) {
-        this.parent = parent;
-        this.qname = qname;
-
-        int tmp = Objects.hashCode(parent);
-        if (qname != null) {
-            tmp = tmp * 31 + qname.hashCode();
-        }
-
-        hash = tmp;
-    }
-
-    public static @NonNull SchemaPath of(final SchemaNodeIdentifier path) {
-        if (path instanceof Absolute) {
-            return of((Absolute) path);
-        } else if (path instanceof Descendant) {
-            return of((Descendant) path);
-        } else {
-            throw new IllegalStateException("Unexpected path " + requireNonNull(path));
-        }
-    }
-
-    public static @NonNull SchemaPath of(final Absolute path) {
-        return SchemaPath.ROOT.createChild(path.getNodeIdentifiers());
-    }
-
-    public static @NonNull SchemaPath of(final Descendant path) {
-        return SchemaPath.SAME.createChild(path.getNodeIdentifiers());
-    }
-
-    /**
-     * Constructs new instance of this class with the concrete path.
-     *
-     * @param path
-     *            list of QName instances which specifies exact path to the
-     *            module node
-     * @param absolute
-     *            boolean value which specifies if the path is absolute or
-     *            relative
-     *
-     * @return A SchemaPath instance.
-     */
-    public static @NonNull SchemaPath create(final Iterable<QName> path, final boolean absolute) {
-        return (absolute ? ROOT : SAME).createChild(path);
-    }
-
-    /**
-     * Constructs new instance of this class with the concrete path.
-     *
-     * @param absolute
-     *            boolean value which specifies if the path is absolute or
-     *            relative
-     * @param element
-     *            a single QName which specifies exact path to the
-     *            module node
-     *
-     * @return A SchemaPath instance.
-     */
-    public static @NonNull SchemaPath create(final boolean absolute, final QName element) {
-        return (absolute ? ROOT : SAME).createChild(element);
-    }
-
-    /**
-     * Constructs new instance of this class with the concrete path.
-     *
-     * @param absolute
-     *            boolean value which specifies if the path is absolute or
-     *            relative
-     * @param path
-     *            one or more QName instances which specifies exact path to the
-     *            module node
-     *
-     * @return A SchemaPath instance.
-     */
-    public static @NonNull SchemaPath create(final boolean absolute, final QName... path) {
-        return create(Arrays.asList(path), absolute);
-    }
-
-    /**
-     * Create a child path based on concatenation of this path and a relative path.
-     *
-     * @param relative Relative path
-     * @return A new child path
-     */
-    public @NonNull SchemaPath createChild(final Iterable<QName> relative) {
-        if (Iterables.isEmpty(relative)) {
-            return this;
-        }
-
-        SchemaPath parentPath = this;
-        for (QName item : relative) {
-            parentPath = parentPath.createChild(item);
-        }
-
-        return parentPath;
-    }
-
-    /**
-     * Create a child path based on concatenation of this path and a relative path.
-     *
-     * @param relative Relative SchemaPath
-     * @return A new child path
-     */
-    public @NonNull SchemaPath createChild(final SchemaPath relative) {
-        checkArgument(!relative.isAbsolute(), "Child creation requires relative path");
-        return createChild(relative.getPathFromRoot());
-    }
-
-    /**
-     * Create a child path based on concatenation of this path and an additional path element.
-     *
-     * @param element Relative SchemaPath elements
-     * @return A new child path
-     */
-    public abstract @NonNull SchemaPath createChild(QName element);
-
-    /**
-     * Create a child path based on concatenation of this path and additional
-     * path elements.
-     *
-     * @param elements Relative SchemaPath elements
-     * @return A new child path
-     */
-    public @NonNull SchemaPath createChild(final QName... elements) {
-        return createChild(Arrays.asList(elements));
-    }
-
-    /**
-     * Returns the list of nodes which need to be traversed to get from the
-     * starting point (root for absolute SchemaPaths) to the node represented
-     * by this object.
-     *
-     * @return list of <code>qname</code> instances which represents
-     *         path from the root to the schema node.
-     */
-    public List<QName> getPathFromRoot() {
-        if (qname == null) {
-            return ImmutableList.of();
-        }
-        return parent == null ? ImmutableList.of(qname) : new PathFromRoot(this);
-    }
-
-    /**
-     * Returns the list of nodes which need to be traversed to get from this
-     * node to the starting point (root for absolute SchemaPaths).
-     *
-     * @return list of <code>qname</code> instances which represents
-     *         path from the schema node towards the root.
-     */
-    public Iterable<QName> getPathTowardsRoot() {
-        return () -> new UnmodifiableIterator<>() {
-            private SchemaPath current = SchemaPath.this;
-
-            @Override
-            public boolean hasNext() {
-                return current.parent != null;
-            }
-
-            @Override
-            public QName next() {
-                if (current.parent != null) {
-                    final QName ret = current.qname;
-                    current = current.parent;
-                    return ret;
-                }
-
-                throw new NoSuchElementException("No more elements available");
-            }
-        };
-    }
-
-    /**
-     * Returns the immediate parent SchemaPath.
-     *
-     * @return Parent path, null if this SchemaPath is already toplevel.
-     */
-    public SchemaPath getParent() {
-        return parent;
-    }
-
-    /**
-     * Get the last component of this path.
-     *
-     * @return The last component of this path.
-     */
-    public final QName getLastComponent() {
-        return qname;
-    }
-
-    /**
-     * Describes whether schema path is|isn't absolute.
-     *
-     * @return boolean value which is <code>true</code> if schema path is
-     *         absolute.
-     */
-    public abstract boolean isAbsolute();
-
-    /**
-     * Return this path as a {@link SchemaNodeIdentifier}.
-     *
-     * @return A SchemaNodeIdentifier.
-     * @throws IllegalStateException if this path is empty
-     */
-    public final SchemaNodeIdentifier asSchemaNodeIdentifier() {
-        checkState(qname != null, "Cannot convert empty %s", this);
-        final List<QName> path = getPathFromRoot();
-        return isAbsolute() ? Absolute.of(path) : Descendant.of(path);
-    }
-
-    /**
-     * Return this path as an {@link Absolute} SchemaNodeIdentifier.
-     *
-     * @return An SchemaNodeIdentifier.
-     * @throws IllegalStateException if this path is empty or is not absolute.
-     */
-    public final Absolute asAbsolute() {
-        final SchemaNodeIdentifier ret = asSchemaNodeIdentifier();
-        if (ret instanceof Absolute) {
-            return (Absolute) ret;
-        }
-        throw new IllegalStateException("Path " + this + " is relative");
-    }
-
-    /**
-     * Return this path as an {@link Descendant} SchemaNodeIdentifier.
-     *
-     * @return An SchemaNodeIdentifier.
-     * @throws IllegalStateException if this path is empty or is not relative.
-     */
-    public final Descendant asDescendant() {
-        final SchemaNodeIdentifier ret = asSchemaNodeIdentifier();
-        if (ret instanceof Descendant) {
-            return (Descendant) ret;
-        }
-        throw new IllegalStateException("Path " + this + " is absolute");
-    }
-
-    @Override
-    public final int hashCode() {
-        return hash;
-    }
-
-    @Override
-    public boolean equals(final Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final SchemaPath other = (SchemaPath) obj;
-        return Objects.equals(qname, other.qname) && Objects.equals(parent, other.parent);
-    }
-
-    @Override
-    public final String toString() {
-        return MoreObjects.toStringHelper(this).add("path", getPathFromRoot()).toString();
-    }
-}