Create unit tests for anydata implemetnation.
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / schema / opaque / AbstractOpaqueDataNodeBuilder.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.util.schema.opaque;
9
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
12
13 import com.google.common.annotations.Beta;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.yangtools.concepts.Builder;
16 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
17 import org.opendaylight.yangtools.yang.data.api.schema.opaque.OpaqueDataNode;
18
19 @Beta
20 public abstract class AbstractOpaqueDataNodeBuilder<T extends OpaqueDataNode> implements Builder<T> {
21     private NodeIdentifier identifier;
22
23     AbstractOpaqueDataNodeBuilder() {
24         // Hidden on purpose
25     }
26
27     final NodeIdentifier identifier() {
28         return identifier;
29     }
30
31     public AbstractOpaqueDataNodeBuilder<T> withIdentifier(final NodeIdentifier newIdentifier) {
32         checkState(identifier == null, "Identifier already set to %s", identifier);
33         identifier = requireNonNull(newIdentifier);
34         return this;
35     }
36
37     public abstract OpaqueDataValueBuilder withValue(Object value);
38
39     @Override
40     public final T build() {
41         checkState(identifier != null, "Identifier not set");
42         return build(identifier);
43     }
44
45     abstract @NonNull T build(@NonNull NodeIdentifier identifier);
46 }