Immutable implementation of new yang-data-api
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / builder / impl / ImmutableLeafSetNodeSchemaAwareBuilder.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 org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
11 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
12 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
13 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
14
15 import com.google.common.base.Preconditions;
16
17 public final class ImmutableLeafSetNodeSchemaAwareBuilder<T> extends ImmutableLeafSetNodeBuilder<T> {
18
19     private final LeafListSchemaNode schema;
20
21     private ImmutableLeafSetNodeSchemaAwareBuilder(LeafListSchemaNode schema) {
22         super();
23         this.schema = schema;
24         super.withNodeIdentifier(new InstanceIdentifier.NodeIdentifier(schema.getQName()));
25     }
26
27     public static <T> ListNodeBuilder<T, LeafSetEntryNode<T>> create(LeafListSchemaNode schema) {
28         return new ImmutableLeafSetNodeSchemaAwareBuilder<>(schema);
29     }
30
31     @Override
32     public ListNodeBuilder<T, LeafSetEntryNode<T>> withChildValue(T value) {
33         // TODO check value type
34         return super.withChildValue(value);
35     }
36
37     @Override
38     public ListNodeBuilder<T, LeafSetEntryNode<T>> withChild(LeafSetEntryNode<T> child) {
39         Preconditions.checkArgument(schema.getQName().equals(child.getNodeType()),
40                 "Incompatible node type, should be: %s, is: %s", schema.getQName(), child.getNodeType());
41         return super.withChild(child);
42     }
43
44     @Override
45     public ListNodeBuilder<T, LeafSetEntryNode<T>> withNodeIdentifier(InstanceIdentifier.NodeIdentifier nodeIdentifier) {
46         throw new UnsupportedOperationException("Node identifier created from schema");
47     }
48 }