Merge "OF plugin classes must have a strict dependency on Connection Service"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-util / src / main / java / org / opendaylight / controller / binding / generator / util / generated / type / builder / ConstantImpl.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.binding.generator.util.generated.type.builder;
9
10 import org.opendaylight.controller.sal.binding.model.api.Constant;
11 import org.opendaylight.controller.sal.binding.model.api.Type;
12
13 final class ConstantImpl implements Constant {
14
15     final Type definingType;
16     private final Type type;
17     private final String name;
18     private final Object value;
19
20     public ConstantImpl(final Type definingType, final Type type,
21                         final String name, final Object value) {
22         super();
23         this.definingType = definingType;
24         this.type = type;
25         this.name = name;
26         this.value = value;
27     }
28
29     @Override
30     public Type getDefiningType() {
31         return definingType;
32     }
33
34     @Override
35     public Type getType() {
36         return type;
37     }
38
39     @Override
40     public String getName() {
41         return name;
42     }
43
44     @Override
45     public Object getValue() {
46         return value;
47     }
48
49     @Override
50     public String toFormattedString() {
51         StringBuilder builder = new StringBuilder();
52         builder.append(type);
53         builder.append(" ");
54         builder.append(name);
55         builder.append(" ");
56         builder.append(value);
57         return builder.toString();
58     }
59
60     /*
61      * (non-Javadoc)
62      *
63      * @see java.lang.Object#hashCode()
64      */
65     @Override
66     public int hashCode() {
67         final int prime = 31;
68         int result = 1;
69         result = prime * result + ((name == null) ? 0 : name.hashCode());
70         result = prime * result + ((type == null) ? 0 : type.hashCode());
71         return result;
72     }
73
74     /*
75      * (non-Javadoc)
76      *
77      * @see java.lang.Object#equals(java.lang.Object)
78      */
79     @Override
80     public boolean equals(Object obj) {
81         if (this == obj) {
82             return true;
83         }
84         if (obj == null) {
85             return false;
86         }
87         if (getClass() != obj.getClass()) {
88             return false;
89         }
90         ConstantImpl other = (ConstantImpl) obj;
91         if (name == null) {
92             if (other.name != null) {
93                 return false;
94             }
95         } else if (!name.equals(other.name)) {
96             return false;
97         }
98         if (type == null) {
99             if (other.type != null) {
100                 return false;
101             }
102         } else if (!type.equals(other.type)) {
103             return false;
104         }
105         if (value == null) {
106             if (other.value != null) {
107                 return false;
108             }
109         } else if (!value.equals(other.value)) {
110             return false;
111         }
112         return true;
113     }
114
115     @Override
116     public String toString() {
117         StringBuilder builder = new StringBuilder();
118         builder.append("Constant [type=");
119         builder.append(type);
120         builder.append(", name=");
121         builder.append(name);
122         builder.append(", value=");
123         builder.append(value);
124         if (definingType != null) {
125             builder.append(", definingType=");
126             builder.append(definingType.getPackageName());
127             builder.append(".");
128             builder.append(definingType.getName());
129         } else {
130             builder.append(", definingType= null");
131         }
132         builder.append("]");
133         return builder.toString();
134     }
135 }