Bug 1411-3: MDSAL Binding2 Generator Util
[mdsal.git] / binding2 / mdsal-binding2-generator-util / src / main / java / org / opendaylight / mdsal / binding2 / generator / util / generated / type / builder / ConstantImpl.java
1 /*
2  * Copyright (c) 2016 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
9 package org.opendaylight.mdsal.binding2.generator.util.generated.type.builder;
10
11 import com.google.common.annotations.Beta;
12 import java.util.Objects;
13 import org.opendaylight.mdsal.binding2.model.api.Constant;
14 import org.opendaylight.mdsal.binding2.model.api.Type;
15
16 @Beta
17 final class ConstantImpl implements Constant {
18
19     private final Type definingType;
20     private final Type type;
21     private final String name;
22     private final Object value;
23
24     public ConstantImpl(final Type definingType, final Type type, final String name, final Object value) {
25         super();
26         this.definingType = definingType;
27         this.type = type;
28         this.name = name;
29         this.value = value;
30     }
31
32
33     @Override
34     public Type getDefiningType() {
35         return definingType;
36     }
37
38     @Override
39     public Type getType() {
40         return type;
41     }
42
43     @Override
44     public String getName() {
45         return name;
46     }
47
48     @Override
49     public Object getValue() {
50         return value;
51     }
52
53     @Override
54     public String toFormattedString() {
55         StringBuilder builder = new StringBuilder();
56         builder.append(type);
57         builder.append(" ");
58         builder.append(name);
59         builder.append(" ");
60         builder.append(value);
61         return builder.toString();
62     }
63
64     @Override
65     public int hashCode() {
66         return Objects.hash(name, type);
67     }
68
69     @Override
70     public boolean equals(final Object obj) {
71         if (this == obj) {
72             return true;
73         }
74         if (obj == null) {
75             return false;
76         }
77         if (getClass() != obj.getClass()) {
78             return false;
79         }
80
81         if (!(obj instanceof ConstantImpl)) {
82             return false;
83         }
84
85         ConstantImpl other = (ConstantImpl) obj;
86         return Objects.equals(name, other.name) && Objects.equals(type, other.type) && Objects.equals(value, other.value);
87     }
88
89     @Override
90     public String toString() {
91         StringBuilder builder = new StringBuilder();
92         builder.append("Constant [type=");
93         builder.append(type);
94         builder.append(", name=");
95         builder.append(name);
96         builder.append(", value=");
97         builder.append(value);
98         if (definingType != null) {
99             builder.append(", definingType=");
100             builder.append(definingType.getPackageName());
101             builder.append(".");
102             builder.append(definingType.getName());
103         } else {
104             builder.append(", definingType= null");
105         }
106         builder.append("]");
107         return builder.toString();
108     }
109 }