Merge "Fixed possible NPE in CodecMapping."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetEntryNodeBuilder.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 org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
13 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedNode;
14
15 import com.google.common.base.Preconditions;
16
17 public class ImmutableLeafSetEntryNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<InstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> {
18
19     public static <T> NormalizedNodeBuilder<InstanceIdentifier.NodeWithValue, T, LeafSetEntryNode<T>> create() {
20         return new ImmutableLeafSetEntryNodeBuilder<>();
21     }
22
23     @Override
24     public LeafSetEntryNode<T> build() {
25         return new ImmutableLeafSetEntryNode<>(nodeIdentifier, value);
26     }
27
28     static final class ImmutableLeafSetEntryNode<T> extends AbstractImmutableNormalizedNode<InstanceIdentifier.NodeWithValue, T> implements LeafSetEntryNode<T> {
29
30         ImmutableLeafSetEntryNode(InstanceIdentifier.NodeWithValue nodeIdentifier, T value) {
31             super(nodeIdentifier, value);
32             Preconditions.checkArgument(nodeIdentifier.getValue().equals(value),
33                     "Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
34         }
35
36         @Override
37         public String toString() {
38             final StringBuffer sb = new StringBuffer("ImmutableLeafSetEntryNode{");
39             sb.append("nodeIdentifier=").append(nodeIdentifier);
40             sb.append(", value=").append(value);
41             sb.append('}');
42             return sb.toString();
43         }
44     }
45 }