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;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeAttrBuilder;
16 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
18 public class ImmutableLeafNodeBuilder<T>
19 extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
21 public static <T> @NonNull NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> create() {
22 return new ImmutableLeafNodeBuilder<>();
26 @SuppressWarnings("unchecked")
27 public LeafNode<T> build() {
28 final T value = getValue();
29 if (value instanceof byte[]) {
30 return (LeafNode<T>) new ImmutableBinaryLeafNode(getNodeIdentifier(), (byte[]) value, getAttributes());
33 return new ImmutableLeafNode<>(getNodeIdentifier(), value, getAttributes());
36 private static final class ImmutableLeafNode<T>
37 extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, T> implements LeafNode<T> {
38 ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value, final Map<QName, String> attributes) {
39 super(nodeIdentifier, value, attributes);
43 private static final class ImmutableBinaryLeafNode
44 extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
45 ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value,
46 final Map<QName, String> attributes) {
47 super(nodeIdentifier, value, attributes);
51 protected byte[] wrapValue(final byte[] valueToWrap) {
52 return valueToWrap.clone();