Populate data/ hierarchy
[yangtools.git] / data / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / AbstractImmutableNormalizedNodeBuilder.java
1 /*
2  * Copyright (c) 2013 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.builder.impl;
9
10 import static com.google.common.base.Preconditions.checkState;
11 import static java.util.Objects.requireNonNull;
12
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
15 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.builder.NormalizedNodeBuilder;
17
18 abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode>
19         implements NormalizedNodeBuilder<I, V, R> {
20     private @Nullable I nodeIdentifier = null;
21     private @Nullable V value = null;
22
23     protected final I getNodeIdentifier() {
24         checkState(nodeIdentifier != null, "Identifier has not been set");
25         return nodeIdentifier;
26     }
27
28     protected final V getValue() {
29         checkState(value != null, "Value has not been set");
30         return value;
31     }
32
33     @Override
34     public NormalizedNodeBuilder<I, V, R> withValue(final V withValue) {
35         this.value = requireNonNull(withValue);
36         return this;
37     }
38
39     @Override
40     public NormalizedNodeBuilder<I, V, R> withNodeIdentifier(final I withNodeIdentifier) {
41         this.nodeIdentifier = requireNonNull(withNodeIdentifier);
42         return this;
43     }
44 }