Merge "Immutable implementation of new yang-data-api"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafNodeBuilder.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.LeafNode;
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 public class ImmutableLeafNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, T, LeafNode<T>> {
16
17     protected ImmutableLeafNodeBuilder() {
18     }
19
20     public static <T> NormalizedNodeBuilder<InstanceIdentifier.NodeIdentifier, T, LeafNode<T>> create() {
21         return new ImmutableLeafNodeBuilder<>();
22     }
23
24     @Override
25     public LeafNode<T> build() {
26         return new ImmutableLeafNode<>(nodeIdentifier, value);
27     }
28
29     static final class ImmutableLeafNode<T> extends AbstractImmutableNormalizedNode<InstanceIdentifier.NodeIdentifier, T> implements LeafNode<T> {
30
31         ImmutableLeafNode(InstanceIdentifier.NodeIdentifier nodeIdentifier, T value) {
32             super(nodeIdentifier, value);
33         }
34
35         @Override
36         public String toString() {
37             final StringBuffer sb = new StringBuffer("ImmutableLeafNode{");
38             sb.append("nodeIdentifier=").append(nodeIdentifier);
39             sb.append(", value=").append(value);
40             sb.append('}');
41             return sb.toString();
42         }
43     }
44 }