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 org.eclipse.jdt.annotation.NonNull;
11 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
12 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
13 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
14 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedSimpleValueNode;
16 public class ImmutableLeafNodeBuilder<T>
17 extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
19 public static <T> @NonNull NormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> create() {
20 return new ImmutableLeafNodeBuilder<>();
24 @SuppressWarnings("unchecked")
25 public LeafNode<T> build() {
26 final T value = getValue();
27 if (value instanceof byte[]) {
28 return (LeafNode<T>) new ImmutableBinaryLeafNode(getNodeIdentifier(), (byte[]) value);
31 return new ImmutableLeafNode<>(getNodeIdentifier(), value);
34 private static final class ImmutableLeafNode<T>
35 extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, T> implements LeafNode<T> {
36 ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value) {
37 super(nodeIdentifier, value);
41 private static final class ImmutableBinaryLeafNode
42 extends AbstractImmutableNormalizedSimpleValueNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
43 ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value) {
44 super(nodeIdentifier, value);
48 protected byte[] wrapValue(final byte[] valueToWrap) {
49 return valueToWrap.clone();