Promote ImmutableNodes to yang-data-spi
[yangtools.git] / data / yang-data-spi / src / main / java / org / opendaylight / yangtools / yang / data / spi / node / impl / ImmutableAnydataNode.java
1 /*
2  * Copyright (c) 2023 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.spi.node.impl;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.AbstractAnydataNode;
15
16 final class ImmutableAnydataNode<V> extends AbstractAnydataNode<V> {
17     private final @NonNull NodeIdentifier name;
18     private final @NonNull V body;
19     private final @NonNull Class<V> objectModel;
20
21     ImmutableAnydataNode(final NodeIdentifier name, final V body, final Class<V> objectModel) {
22         this.name = requireNonNull(name);
23         this.body = requireNonNull(body);
24         this.objectModel = requireNonNull(objectModel);
25     }
26
27     @Override
28     public NodeIdentifier name() {
29         return name;
30     }
31
32     @Override
33     public Class<V> bodyObjectModel() {
34         return objectModel;
35     }
36
37     @Override
38     protected V value() {
39         return body;
40     }
41
42     @Override
43     protected V wrappedValue() {
44         return body;
45     }
46 }