Fix checkstyle issues reported by odlparent-3.0.0's checkstyle
[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 java.util.Map;
11 import org.opendaylight.yangtools.yang.common.QName;
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.NormalizedNodeAttrBuilder;
15 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
16
17 public class ImmutableLeafNodeBuilder<T>
18         extends AbstractImmutableNormalizedNodeBuilder<NodeIdentifier, T, LeafNode<T>> {
19
20     public static <T> NormalizedNodeAttrBuilder<NodeIdentifier, T, LeafNode<T>> create() {
21         return new ImmutableLeafNodeBuilder<>();
22     }
23
24     @Override
25     @SuppressWarnings("unchecked")
26     public LeafNode<T> build() {
27         final T value = getValue();
28         if (value instanceof byte[]) {
29             return (LeafNode<T>) new ImmutableBinaryLeafNode(getNodeIdentifier(), (byte[]) value, getAttributes());
30         }
31
32         return new ImmutableLeafNode<>(getNodeIdentifier(), value, getAttributes());
33     }
34
35     private static final class ImmutableLeafNode<T>
36             extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, T> implements LeafNode<T> {
37         ImmutableLeafNode(final NodeIdentifier nodeIdentifier, final T value, final Map<QName, String> attributes) {
38             super(nodeIdentifier, value, attributes);
39         }
40     }
41
42     private static final class ImmutableBinaryLeafNode
43             extends AbstractImmutableNormalizedValueAttrNode<NodeIdentifier, byte[]> implements LeafNode<byte[]> {
44         ImmutableBinaryLeafNode(final NodeIdentifier nodeIdentifier, final byte[] value,
45             final Map<QName, String> attributes) {
46             super(nodeIdentifier, value, attributes);
47         }
48
49         @Override
50         protected byte[] wrapValue(final byte[] valueToWrap) {
51             return valueToWrap.clone();
52         }
53     }
54 }