e388aca40c2035e214d62fe7106e0d70f1a32cae
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetEntryNodeSchemaAwareBuilder.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 static java.util.Objects.requireNonNull;
11
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
14 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
15 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeBuilder;
16 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
17
18 public final class ImmutableLeafSetEntryNodeSchemaAwareBuilder<T> extends ImmutableLeafSetEntryNodeBuilder<T> {
19     private final LeafListSchemaNode schema;
20
21     private ImmutableLeafSetEntryNodeSchemaAwareBuilder(final LeafListSchemaNode schema) {
22         this.schema = requireNonNull(schema);
23     }
24
25     public static <T> @NonNull NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> create(
26             final LeafListSchemaNode schema) {
27         return new ImmutableLeafSetEntryNodeSchemaAwareBuilder<>(schema);
28     }
29
30     @Override
31     public NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withValue(final T withValue) {
32         super.withNodeIdentifier(new NodeWithValue<>(schema.getQName(), withValue));
33         // TODO check value type using TypeProvider ?
34         return super.withValue(withValue);
35     }
36
37     @Override
38     public NormalizedNodeBuilder<NodeWithValue, T, LeafSetEntryNode<T>> withNodeIdentifier(
39             final NodeWithValue withNodeIdentifier) {
40         throw new UnsupportedOperationException("Node identifier created from schema");
41     }
42 }