63e4470878ce55d28a5931c27d134697103e6326
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetEntryNodeBuilder.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 com.google.common.base.Preconditions;
11 import java.util.Map;
12 import java.util.Objects;
13 import org.opendaylight.yangtools.yang.common.QName;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
15 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
16 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
17
18 public class ImmutableLeafSetEntryNodeBuilder<T>
19         extends AbstractImmutableNormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> {
20
21     public static <T> ImmutableLeafSetEntryNodeBuilder<T> create() {
22         return new ImmutableLeafSetEntryNodeBuilder<>();
23     }
24
25     @Override
26     public LeafSetEntryNode<T> build() {
27         return new ImmutableLeafSetEntryNode<>(getNodeIdentifier(), getValue(), getAttributes());
28     }
29
30     private static final class ImmutableLeafSetEntryNode<T>
31             extends AbstractImmutableNormalizedValueAttrNode<NodeWithValue, T> implements LeafSetEntryNode<T> {
32
33         ImmutableLeafSetEntryNode(final NodeWithValue nodeIdentifier, final T value,
34                 final Map<QName, String> attributes) {
35             super(nodeIdentifier, value, attributes);
36             Preconditions.checkArgument(Objects.deepEquals(nodeIdentifier.getValue(), value),
37                     "Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
38         }
39     }
40 }