Merge "Documentation generator improvements."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / util / AbstractNodeBuilder.java
1 package org.opendaylight.yangtools.yang.data.impl.util;
2
3 import java.net.URI;
4 import java.util.Date;
5 import java.util.Map;
6 import java.util.concurrent.ConcurrentHashMap;
7
8 import org.opendaylight.yangtools.yang.common.QName;
9 import org.opendaylight.yangtools.yang.data.api.Node;
10
11 public abstract class AbstractNodeBuilder<P extends Node<?>, T extends NodeBuilder<P, T>> implements NodeBuilder<P, T> {
12
13     private final Map<QName, String> attributes;
14     private QName qName;
15
16     public AbstractNodeBuilder() {
17         this.attributes = new ConcurrentHashMap<>();
18     }
19
20     public AbstractNodeBuilder(QName nodeType, Map<QName, String> attributes) {
21         super();
22         this.qName = nodeType;
23         this.attributes = new ConcurrentHashMap<>(attributes);
24     }
25
26     public AbstractNodeBuilder(QName nodeType) {
27         this.qName = nodeType;
28         this.attributes = new ConcurrentHashMap<>();
29     }
30
31     @SuppressWarnings("unchecked")
32     protected final T thisInstance() {
33         return (T) this;
34     }
35
36     @Override
37     public final T setQName(QName name) {
38         this.qName = name;
39         return thisInstance();
40     }
41
42     public QName getQName() {
43         return qName;
44     }
45
46     @Override
47     public final T setAttribute(QName attrName, String attrValue) {
48         attributes.put(attrName, attrValue);
49         return thisInstance();
50     }
51
52     public Map<QName, String> getAttributes() {
53         return attributes;
54     }
55     
56     @Override
57     public T setAttribute(String attrName, String attrValue) {
58         attributes.put(QName.create(qName, attrName), attrValue);
59         return thisInstance();
60     }
61
62 }