2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
14 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
15 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
17 public class ImmutableLeafNodeBuilder<T>
18 extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
20 public static <T> @NonNull NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> create() {
21 return new ImmutableLeafNodeBuilder<>();
25 @SuppressWarnings("unchecked")
26 public static <T> @NonNull LeafNode<T> createNode(final NodeIdentifier identifier, final T value) {
27 if (value instanceof byte[]) {
28 return (LeafNode<T>) new ImmutableBinaryLeafNode(identifier, (byte[]) value);
30 return new ImmutableLeafNode<>(identifier, value);
34 public LeafNode<T> build() {
35 return createNode(getNodeIdentifier(), getValue());
38 private static final class ImmutableLeafNode<T>
39 extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, T> implements LeafNode<T> {
40 ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value) {
41 super(nodeIdentifier, value);
45 private static final class ImmutableBinaryLeafNode
46 extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
47 ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value) {
48 super(nodeIdentifier, value);
52 protected byte[] wrapValue(final byte[] valueToWrap) {
53 return valueToWrap.clone();