BUG-4295: instantiate MERGE operations lazily
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / ContainerModificationStrategy.java
1 /*
2  * Copyright (c) 2015 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.impl.schema.tree;
9
10 import static com.google.common.base.Preconditions.checkArgument;
11
12 import com.google.common.base.Preconditions;
13 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
18 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
19
20 /**
21  * General container modification strategy. Used by {@link PresenceContainerModificationStrategy} via subclassing
22  * and by {@link StructuralContainerModificationStrategy} as a delegate.
23  */
24 class ContainerModificationStrategy extends AbstractDataNodeContainerModificationStrategy<ContainerSchemaNode> {
25     ContainerModificationStrategy(final ContainerSchemaNode schemaNode, final TreeType treeType) {
26         super(schemaNode, ContainerNode.class, treeType);
27     }
28
29     @Override
30     @SuppressWarnings("rawtypes")
31     protected final DataContainerNodeBuilder createBuilder(final NormalizedNode<?, ?> original) {
32         checkArgument(original instanceof ContainerNode);
33         return ImmutableContainerNodeBuilder.create((ContainerNode) original);
34     }
35
36     @Override
37     protected NormalizedNode<?, ?> createEmptyValue(NormalizedNode<?, ?> original) {
38         Preconditions.checkArgument(original instanceof ContainerNode);
39         return ImmutableContainerNodeBuilder.create().withNodeIdentifier(((ContainerNode) original).getIdentifier())
40                 .build();
41     }
42 }