Merge "Fix for messags at the boot up time This commit proposes following two sets...
[controller.git] / opendaylight / sal / yang-prototype / yang / yang-model-util / src / main / java / org / opendaylight / controller / yang / model / util / UnionType.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.controller.yang.model.util;
9
10 import java.util.Collections;
11 import java.util.List;
12
13 import org.opendaylight.controller.yang.common.QName;
14 import org.opendaylight.controller.yang.model.api.SchemaPath;
15 import org.opendaylight.controller.yang.model.api.Status;
16 import org.opendaylight.controller.yang.model.api.TypeDefinition;
17 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
18 import org.opendaylight.controller.yang.model.api.type.UnionTypeDefinition;
19
20 public class UnionType implements UnionTypeDefinition {
21
22     private final QName name = BaseTypes.constructQName("union");
23     private final SchemaPath path = BaseTypes.schemaPath(name);
24     private final String description = "The union built-in type represents a value that corresponds to one of its member types.";
25     private final String reference = "https://tools.ietf.org/html/rfc6020#section-9.12";
26
27     private final List<TypeDefinition<?>> types;
28
29
30     public UnionType(List<TypeDefinition<?>> types) {
31         if(types == null) {
32             throw new NullPointerException("When the type is 'union', the 'type' statement MUST be present.");
33         }
34         this.types = types;
35     }
36
37     @Override
38     public UnionTypeDefinition getBaseType() {
39         return this;
40     }
41
42     @Override
43     public String getUnits() {
44         return null;
45     }
46
47     @Override
48     public Object getDefaultValue() {
49         return null;
50     }
51
52     @Override
53     public QName getQName() {
54         return name;
55     }
56
57     @Override
58     public SchemaPath getPath() {
59         return path;
60     }
61
62     @Override
63     public String getDescription() {
64         return description;
65     }
66
67     @Override
68     public String getReference() {
69         return reference;
70     }
71
72     @Override
73     public Status getStatus() {
74         return Status.CURRENT;
75     }
76
77     @Override
78     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
79         return Collections.emptyList();
80     }
81
82     @Override
83     public List<TypeDefinition<?>> getTypes() {
84         return types;
85     }
86
87     @Override
88     public int hashCode() {
89         // TODO: implement hashcode
90         return 4;
91     }
92
93     @Override
94     public boolean equals(Object obj) {
95         if (this == obj) {
96             return true;
97         }
98         if (obj == null) {
99             return false;
100         }
101         if (getClass() != obj.getClass()) {
102             return false;
103         }
104         UnionType other = (UnionType) obj;
105         if (types == null) {
106             if (other.types != null) {
107                 return false;
108             }
109         } else if (!types.equals(other.types)) {
110             return false;
111         }
112         return true;
113     }
114
115     @Override
116     public String toString() {
117         StringBuilder builder = new StringBuilder();
118         builder.append("UnionType [name=");
119         builder.append(name);
120         builder.append(", types=[");
121         for(TypeDefinition<?> td : types) {
122             builder.append(", "+ td.getQName().getLocalName());
123         }
124         builder.append("]");
125         builder.append("]");
126         return builder.toString();
127     }
128
129 }