338b4c71ccdaabcb86dfced53c74403e7c1a262c
[yangtools.git] / yang / 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.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
16
17 abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V, R extends NormalizedNode<I, ?>>
18         implements NormalizedNodeBuilder<I, V, R> {
19     private I nodeIdentifier;
20     private V value;
21
22     protected final I getNodeIdentifier() {
23         checkState(nodeIdentifier != null, "Identifier has not been set");
24         return nodeIdentifier;
25     }
26
27     protected final V getValue() {
28         checkState(value != null, "Value has not been set");
29         return value;
30     }
31
32     @Override
33     public NormalizedNodeBuilder<I, V, R> withValue(final V withValue) {
34         this.value = requireNonNull(withValue);
35         return this;
36     }
37
38     @Override
39     public NormalizedNodeBuilder<I, V, R> withNodeIdentifier(final I withNodeIdentifier) {
40         this.nodeIdentifier = requireNonNull(withNodeIdentifier);
41         return this;
42     }
43 }