Split out yang-data-tree-{api,spi}
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / LeafSetModificationStrategy.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.impl.schema.tree;
9
10 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
14 import org.opendaylight.yangtools.yang.data.api.schema.SystemLeafSetNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.UserLeafSetNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableUserLeafSetNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.Invisible;
19 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
20 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
21
22 final class LeafSetModificationStrategy extends Invisible<LeafListSchemaNode> {
23     @SuppressWarnings({ "unchecked", "rawtypes" })
24     private static final NormalizedNodeContainerSupport<NodeIdentifier, UserLeafSetNode<?>> ORDERED_SUPPORT =
25             new NormalizedNodeContainerSupport(UserLeafSetNode.class, ChildTrackingPolicy.ORDERED,
26                 foo -> ImmutableUserLeafSetNodeBuilder.create((UserLeafSetNode<?>)foo),
27                 ImmutableUserLeafSetNodeBuilder::create);
28     @SuppressWarnings({ "unchecked", "rawtypes" })
29     private static final NormalizedNodeContainerSupport<NodeIdentifier, SystemLeafSetNode<?>> UNORDERED_SUPPORT =
30             new NormalizedNodeContainerSupport(SystemLeafSetNode.class,
31                 foo -> ImmutableLeafSetNodeBuilder.create((SystemLeafSetNode<?>)foo),
32                 ImmutableLeafSetNodeBuilder::create);
33
34     LeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
35         super(schema.isUserOrdered() ? ORDERED_SUPPORT : UNORDERED_SUPPORT, treeConfig,
36                 new ValueNodeModificationStrategy<>(LeafSetEntryNode.class, schema));
37     }
38
39     @Override
40     public ModificationApplyOperation childByArg(final PathArgument arg) {
41         return arg instanceof NodeWithValue ? entryStrategy() : null;
42     }
43 }