4b4005db6bde4c2a4f4852b5d010f481dcf1fb69
[yangtools.git] / data / yang-data-tree-ri / src / main / java / org / opendaylight / yangtools / yang / data / tree / impl / NodeModification.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.tree.impl;
9
10 import java.util.Collection;
11 import java.util.Optional;
12 import org.opendaylight.yangtools.concepts.Identifiable;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.tree.impl.node.TreeNode;
15
16 /**
17  * Internal interface representing a modification action of a particular node. It is used by the validation code to
18  * allow for a read-only view of the modification tree as we should never modify that during validation.
19  */
20 abstract sealed class NodeModification implements Identifiable<PathArgument> permits ModifiedNode {
21     /**
22      * Get the type of modification.
23      *
24      * @return Operation type.
25      */
26     abstract LogicalOperation getOperation();
27
28     /**
29      * Get the original tree node to which the modification is to be applied.
30      *
31      * @return The original node, or {@link Optional#absent()} if the node is
32      *         a new node.
33      */
34     abstract Optional<? extends TreeNode> getOriginal();
35
36     /**
37      * Get a read-only view of children nodes.
38      *
39      * @return Collection of all children nodes.
40      */
41     abstract Collection<? extends NodeModification> getChildren();
42
43     /**
44      * A shortcut to {@code getChildren().isEmpty()}.
45      *
46      * @return {@code} if {@link #getChildren()} is empty.
47      */
48     abstract boolean isEmpty();
49 }