Rework NormalizedNode type hierarchy
[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 @NonNull Class<V> objectModel;
23
24     ImmutableAnydataNodeBuilder(final Class<V> objectModel) {
25         this.objectModel = requireNonNull(objectModel);
26     }
27
28     public static <V> NormalizedNodeBuilder<NodeIdentifier, V, AnydataNode<V>> create(final Class<V> objectModel) {
29         return new ImmutableAnydataNodeBuilder<>(objectModel);
30     }
31
32     @Override
33     public AnydataNode<V> build() {
34         return new ImmutableAnydataNode<>(getNodeIdentifier(), getValue(), objectModel);
35     }
36
37     private static final class ImmutableAnydataNode<V>
38             extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, AnydataNode<?>, V>
39             implements AnydataNode<V> {
40         private final 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> bodyObjectModel() {
49             return objectModel;
50         }
51
52         @Override
53         protected Class<AnydataNode<?>> implementedType() {
54             return (Class) AnydataNode.class;
55         }
56     }
57 }