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.EffectiveModelContext;
17 * The NormalizedNodePruner removes all nodes from the input NormalizedNode that do not have a corresponding
18 * schema element in the passed in SchemaContext. Instances of this class can be reused multiple times and must be
19 * initialized before each use through {@link #initializeForPath(YangInstanceIdentifier)}.
22 public abstract class ReusableNormalizedNodePruner extends AbstractNormalizedNodePruner {
23 private static final class SimplePruner extends ReusableNormalizedNodePruner {
24 SimplePruner(final EffectiveModelContext schemaContext) {
28 SimplePruner(final DataSchemaContextTree tree) {
33 public ReusableNormalizedNodePruner duplicate() {
34 return new SimplePruner(getTree());
38 ReusableNormalizedNodePruner(final EffectiveModelContext schemaContext) {
42 ReusableNormalizedNodePruner(final DataSchemaContextTree tree) {
47 * Create a new pruner bound to a SchemaContext.
49 * @param schemaContext SchemaContext to use
50 * @return A new uninitialized pruner
51 * @throws NullPointerException if {@code schemaContext} is null
53 public static @NonNull ReusableNormalizedNodePruner forSchemaContext(final EffectiveModelContext schemaContext) {
54 return new SimplePruner(schemaContext);
58 * Create a new pruner bound to a DataSchemaContextTree. This is a more efficient alternative of
59 * {@link #forSchemaContext(EffectiveModelContext)}.
61 * @param tree DataSchemaContextTree to use
62 * @return A new uninitialized pruner
63 * @throws NullPointerException if {@code schemaContext} is null
65 public static @NonNull ReusableNormalizedNodePruner forDataSchemaContext(final DataSchemaContextTree tree) {
66 return new SimplePruner(tree);
70 * Return a new instance, which is backed but the same DataSchemaContextTree, but does not share any state and is
71 * uninitialized. This is equivalent to {@link #forDataSchemaContext(DataSchemaContextTree)} and is provided for
74 * @return A new uninitialized pruner bound to the same SchemaContext as this one.
76 public abstract @NonNull ReusableNormalizedNodePruner duplicate();
79 * Initialize this pruner for processing a node at specified path.
81 * @param path Path that will be processed next
82 * @throws NullPointerException if {@code path} is null
84 public final void initializeForPath(final YangInstanceIdentifier path) {
88 public final @NonNull ReusableNormalizedNodePruner withUintAdaption() {
89 return new UintAdaptingPruner(getTree());