Merge branch 'master' of ../controller
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableAnydataNodeBuilder.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.builder.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.annotations.Beta;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
15 import org.opendaylight.yangtools.yang.data.api.schema.AnydataNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
17 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
18
19 @Beta
20 public class ImmutableAnydataNodeBuilder<V>
21         extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> {
22     private final Class<V> objectModel;
23
24     ImmutableAnydataNodeBuilder(final Class<V> objectModel) {
25         this.objectModel = requireNonNull(objectModel);
26     }
27
28     public static <V> @NonNull NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> create(
29             final Class<V> objectModel) {
30         return new ImmutableAnydataNodeBuilder<>(objectModel);
31     }
32
33     @Override
34     public AnydataNode<V> build() {
35         return new ImmutableAnydataNode<>(getNodeIdentifier(), getValue(), objectModel);
36     }
37
38     private static final class ImmutableAnydataNode<V>
39             extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, V> implements AnydataNode<V> {
40         private final @NonNull Class<V> objectModel;
41
42         protected ImmutableAnydataNode(final NodeIdentifier nodeIdentifier, final V value, final Class<V> objectModel) {
43             super(nodeIdentifier, value);
44             this.objectModel = requireNonNull(objectModel);
45         }
46
47         @Override
48         public Class<V> getValueObjectModel() {
49             return objectModel;
50         }
51     }
52 }