6e3f15d3f8eaa1c65dbe5109d65516bce927843f
[yangtools.git] / yang / 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.LeafSetNode;
15 import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
17 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableOrderedLeafSetNodeBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.tree.AbstractNodeContainerModificationStrategy.Invisible;
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, OrderedLeafSetNode<?>> ORDERED_SUPPORT =
25             new NormalizedNodeContainerSupport(OrderedLeafSetNode.class, ChildTrackingPolicy.ORDERED,
26                 foo -> ImmutableOrderedLeafSetNodeBuilder.create((OrderedLeafSetNode<?>)foo),
27                 ImmutableOrderedLeafSetNodeBuilder::create);
28     @SuppressWarnings({ "unchecked", "rawtypes" })
29     private static final NormalizedNodeContainerSupport<NodeIdentifier, LeafSetNode<?>> UNORDERED_SUPPORT =
30             new NormalizedNodeContainerSupport(LeafSetNode.class,
31                 foo -> ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>)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 }