ba351f13481c7491c963f5063dc6ed17931d2b5c
[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 java.util.Map;
11
12 import org.opendaylight.yangtools.yang.common.QName;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.nodes.AbstractImmutableNormalizedValueAttrNode;
16
17 import com.google.common.base.Preconditions;
18
19 public class ImmutableLeafSetEntryNodeBuilder<T> extends AbstractImmutableNormalizedNodeBuilder<InstanceIdentifier.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> extends AbstractImmutableNormalizedValueAttrNode<InstanceIdentifier.NodeWithValue, T> implements LeafSetEntryNode<T> {
31
32         ImmutableLeafSetEntryNode(final InstanceIdentifier.NodeWithValue nodeIdentifier, final T value, final Map<QName, String> attributes) {
33             super(nodeIdentifier, value, attributes);
34             Preconditions.checkArgument(nodeIdentifier.getValue().equals(value),
35                     "Node identifier contains different value: %s than value itself: %s", nodeIdentifier, value);
36         }
37     }
38 }