Fix minor bug in FRM proactive flow code path
[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 final class UnionType implements UnionTypeDefinition {
21
22     private final QName name = BaseTypes.constructQName("union");
23     private final SchemaPath path;
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     private final UnionTypeDefinition baseType;
27     private final List<TypeDefinition<?>> types;
28
29     private UnionType(List<TypeDefinition<?>> types) {
30         if (types == null) {
31             throw new NullPointerException(
32                     "When the type is 'union', the 'type' statement MUST be present.");
33         }
34         path = BaseTypes.schemaPath(name);
35         this.types = types;
36         this.baseType = this;
37     }
38
39     public UnionType(final SchemaPath path, List<TypeDefinition<?>> types) {
40         if (types == null) {
41             throw new NullPointerException(
42                     "When the type is 'union', the 'type' statement MUST be present.");
43         }
44         this.path = path;
45         this.types = types;
46         this.baseType = new UnionType(types);
47     }
48
49     @Override
50     public UnionTypeDefinition getBaseType() {
51         return baseType;
52     }
53
54     @Override
55     public String getUnits() {
56         return null;
57     }
58
59     @Override
60     public Object getDefaultValue() {
61         return null;
62     }
63
64     @Override
65     public QName getQName() {
66         return name;
67     }
68
69     @Override
70     public SchemaPath getPath() {
71         return path;
72     }
73
74     @Override
75     public String getDescription() {
76         return description;
77     }
78
79     @Override
80     public String getReference() {
81         return reference;
82     }
83
84     @Override
85     public Status getStatus() {
86         return Status.CURRENT;
87     }
88
89     @Override
90     public List<UnknownSchemaNode> getUnknownSchemaNodes() {
91         return Collections.emptyList();
92     }
93
94     @Override
95     public List<TypeDefinition<?>> getTypes() {
96         return types;
97     }
98
99     @Override
100     public int hashCode() {
101         final int prime = 31;
102         int result = 1;
103         result = prime * result + ((name == null) ? 0 : name.hashCode());
104         result = prime * result + ((path == null) ? 0 : path.hashCode());
105         result = prime * result + ((types == null) ? 0 : types.hashCode());
106         return result;
107     }
108
109     @Override
110     public boolean equals(Object obj) {
111         if (this == obj) {
112             return true;
113         }
114         if (obj == null) {
115             return false;
116         }
117         if (getClass() != obj.getClass()) {
118             return false;
119         }
120         UnionType other = (UnionType) obj;
121         if (types == null) {
122             if (other.types != null) {
123                 return false;
124             }
125         } else if (!types.equals(other.types)) {
126             return false;
127         }
128         return true;
129     }
130
131     @Override
132     public String toString() {
133         StringBuilder builder = new StringBuilder();
134         builder.append("UnionType [name=");
135         builder.append(name);
136         builder.append(", types=[");
137         for (TypeDefinition<?> td : types) {
138             builder.append(", " + td.getQName().getLocalName());
139         }
140         builder.append("]");
141         builder.append("]");
142         return builder.toString();
143     }
144
145 }