Cleanup use of Guava library
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / UnorderedLeafSetModificationStrategy.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 static com.google.common.base.Preconditions.checkArgument;
11
12 import java.util.Optional;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
18 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
19 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafSetNodeBuilder;
20 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
21
22 final class UnorderedLeafSetModificationStrategy extends AbstractNodeContainerModificationStrategy {
23     private final Optional<ModificationApplyOperation> entryStrategy;
24
25     @SuppressWarnings({ "unchecked", "rawtypes" })
26     UnorderedLeafSetModificationStrategy(final LeafListSchemaNode schema, final DataTreeConfiguration treeConfig) {
27         super((Class) LeafSetNode.class, treeConfig);
28         entryStrategy = Optional.of(new LeafSetEntryModificationStrategy(schema));
29     }
30
31     @SuppressWarnings("rawtypes")
32     @Override
33     protected NormalizedNodeContainerBuilder createBuilder(final NormalizedNode<?, ?> original) {
34         checkArgument(original instanceof LeafSetNode<?>);
35         return ImmutableLeafSetNodeBuilder.create((LeafSetNode<?>) original);
36     }
37
38     @Override
39     protected NormalizedNode<?, ?> createEmptyValue(final NormalizedNode<?, ?> original) {
40         checkArgument(original instanceof LeafSetNode<?>);
41         return ImmutableLeafSetNodeBuilder.create().withNodeIdentifier(((LeafSetNode<?>) original).getIdentifier())
42                 .build();
43     }
44
45     @Override
46     public Optional<ModificationApplyOperation> getChild(final PathArgument identifier) {
47         return identifier instanceof NodeWithValue ? entryStrategy : Optional.empty();
48     }
49 }