Bug 6859: Binding generator v1 refactoring
[mdsal.git] / binding / mdsal-binding-generator-util / src / main / java / org / opendaylight / mdsal / binding / model / 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.mdsal.binding.model.util.generated.type.builder;
9
10 import java.util.Objects;
11 import org.opendaylight.mdsal.binding.model.api.Constant;
12 import org.opendaylight.mdsal.binding.model.api.Type;
13
14 final class ConstantImpl implements Constant {
15
16     private final Type definingType;
17     private final Type type;
18     private final String name;
19     private final Object value;
20
21     public ConstantImpl(final Type definingType, final Type type, 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 this.definingType;
32     }
33
34     @Override
35     public Type getType() {
36         return this.type;
37     }
38
39     @Override
40     public String getName() {
41         return this.name;
42     }
43
44     @Override
45     public Object getValue() {
46         return this.value;
47     }
48
49     @Override
50     public String toFormattedString() {
51         final StringBuilder builder = new StringBuilder();
52         builder.append(this.type);
53         builder.append(" ");
54         builder.append(this.name);
55         builder.append(" ");
56         builder.append(this.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) + Objects.hashCode(this.name);
70         result = (prime * result) + Objects.hashCode(this.type);
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(final 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         final ConstantImpl other = (ConstantImpl) obj;
91         return Objects.equals(this.name, other.name) && Objects.equals(this.type, other.type) && Objects.equals(this.value, other.value);
92     }
93
94     @Override
95     public String toString() {
96         final StringBuilder builder = new StringBuilder();
97         builder.append("Constant [type=");
98         builder.append(this.type);
99         builder.append(", name=");
100         builder.append(this.name);
101         builder.append(", value=");
102         builder.append(this.value);
103         if (this.definingType != null) {
104             builder.append(", definingType=");
105             builder.append(this.definingType.getPackageName());
106             builder.append(".");
107             builder.append(this.definingType.getName());
108         } else {
109             builder.append(", definingType= null");
110         }
111         builder.append("]");
112         return builder.toString();
113     }
114 }