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