2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.datastore.node.utils.transformer;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
13 import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
14 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17 * The NormalizedNodePruner removes all nodes from the input NormalizedNode that do not have a corresponding
18 * schema element in the passed in SchemaContext.
21 * Unlike {@link NormalizedNodePruner}, this class can be reused multiple times and must be initialized before each use
22 * through {@link #initializeForPath(YangInstanceIdentifier)}.
25 public final class ReusableNormalizedNodePruner extends AbstractNormalizedNodePruner {
26 private ReusableNormalizedNodePruner(final SchemaContext schemaContext) {
30 private ReusableNormalizedNodePruner(final DataSchemaContextTree tree) {
35 * Create a new pruner bound to a SchemaContext.
37 * @param schemaContext SchemaContext to use
38 * @return A new uninitialized pruner
39 * @throws NullPointerException if {@code schemaContext} is null
41 public static @NonNull ReusableNormalizedNodePruner forSchemaContext(final SchemaContext schemaContext) {
42 return new ReusableNormalizedNodePruner(schemaContext);
46 * Create a new pruner bound to a DataSchemaContextTree. This is a more efficient alternative of
47 * {@link #forSchemaContext(SchemaContext)}.
49 * @param tree DataSchemaContextTree to use
50 * @return A new uninitialized pruner
51 * @throws NullPointerException if {@code schemaContext} is null
53 public static @NonNull ReusableNormalizedNodePruner forDataSchemaContext(final DataSchemaContextTree tree) {
54 return new ReusableNormalizedNodePruner(tree);
58 * Return a new instance, which is backed but the same DataSchemaContextTree, but does not share any state and is
59 * uninitialized. This is equivalent to {@link #forDataSchemaContext(DataSchemaContextTree)} and is provided for
62 * @return A new uninitialized pruner bound to the same SchemaContext as this one.
64 public @NonNull ReusableNormalizedNodePruner duplicate() {
65 return new ReusableNormalizedNodePruner(getTree());
69 * Initialize this pruner for processing a node at specified path.
71 * @param path Path that will be processed next
72 * @throws NullPointerException if {@code path} is null
74 public void initializeForPath(final YangInstanceIdentifier path) {