Bug 499: Initial implementation of supporting tree structures
[controller.git] / opendaylight / md-sal / sal-dom-broker / src / main / java / org / opendaylight / controller / md / sal / dom / store / impl / tree / StoreNodeCompositeBuilder.java
1 /*
2  * Copyright (c) 2014 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.controller.md.sal.dom.store.impl.tree;
9
10 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
11 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.NormalizedNodeContainerBuilder;
12
13 /**
14  *
15  * Helper builder
16  *
17  *
18  */
19 @SuppressWarnings("rawtypes")
20 public class StoreNodeCompositeBuilder {
21
22     private final StoreMetadataNode.Builder metadata;
23
24     private final NormalizedNodeContainerBuilder data;
25
26
27     private StoreNodeCompositeBuilder(final NormalizedNodeContainerBuilder nodeBuilder) {
28         this.metadata = StoreMetadataNode.builder();
29         this.data = nodeBuilder;
30     }
31
32     @SuppressWarnings("unchecked")
33     public StoreNodeCompositeBuilder add(final StoreMetadataNode node) {
34         metadata.add(node);
35         data.addChild(node.getData());
36         return this;
37     }
38
39
40     public StoreMetadataNode build() {
41         return metadata.setData(data.build()).build();
42     }
43
44
45     public static StoreNodeCompositeBuilder from(final NormalizedNodeContainerBuilder nodeBuilder) {
46         return new StoreNodeCompositeBuilder(nodeBuilder);
47     }
48
49     public static StoreNodeCompositeBuilder from(final StoreMetadataNode previous, final NormalizedNodeContainerBuilder nodeBuilder) {
50
51         return new StoreNodeCompositeBuilder(nodeBuilder);
52     }
53
54     public StoreNodeCompositeBuilder setIdentifier(final PathArgument identifier) {
55         data.withNodeIdentifier(identifier);
56         return this;
57     }
58
59 }