2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
8 package org.opendaylight.controller.sal.binding.generator.impl;
\r
10 import org.opendaylight.controller.sal.binding.model.api.Constant;
\r
11 import org.opendaylight.controller.sal.binding.model.api.Type;
\r
12 import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
\r
14 final class ConstantBuilderImpl implements ConstantBuilder {
\r
16 private final Type type;
\r
17 private final String name;
\r
18 private Object value;
\r
20 public ConstantBuilderImpl(Type type, String name, Object value) {
\r
27 public ConstantBuilderImpl(Type type, String name) {
\r
34 public void assignValue(Object value) {
\r
39 public Constant toInstance(final Type definingType) {
\r
40 return new ConstantImpl(definingType, type, name, value);
\r
43 private static final class ConstantImpl implements Constant {
\r
45 final Type definingType;
\r
46 private final Type type;
\r
47 private final String name;
\r
48 private final Object value;
\r
50 public ConstantImpl(final Type definingType, final Type type,
\r
51 final String name, final Object value) {
\r
53 this.definingType = definingType;
\r
60 public Type getDefiningType() {
\r
61 return definingType;
\r
65 public Type getType() {
\r
70 public String getName() {
\r
75 public Object getValue() {
\r
80 public String toFormattedString() {
\r
81 StringBuilder builder = new StringBuilder();
\r
82 builder.append(type);
\r
83 builder.append(" ");
\r
84 builder.append(name);
\r
85 builder.append(" ");
\r
86 builder.append(value);
\r
87 return builder.toString();
\r
93 * @see java.lang.Object#hashCode()
\r
96 public int hashCode() {
\r
97 final int prime = 31;
\r
99 result = prime * result + ((name == null) ? 0 : name.hashCode());
\r
100 result = prime * result + ((type == null) ? 0 : type.hashCode());
\r
101 result = prime * result + ((value == null) ? 0 : value.hashCode());
\r
102 if (definingType != null) {
\r
105 + ((definingType.getPackageName() == null) ? 0
\r
106 : definingType.getPackageName().hashCode());
\r
109 + ((definingType.getName() == null) ? 0 : definingType
\r
110 .getName().hashCode());
\r
118 * @see java.lang.Object#equals(java.lang.Object)
\r
121 public boolean equals(Object obj) {
\r
128 if (getClass() != obj.getClass()) {
\r
131 ConstantImpl other = (ConstantImpl) obj;
\r
132 if (name == null) {
\r
133 if (other.name != null) {
\r
136 } else if (!name.equals(other.name)) {
\r
139 if (type == null) {
\r
140 if (other.type != null) {
\r
143 } else if (!type.equals(other.type)) {
\r
146 if (value == null) {
\r
147 if (other.value != null) {
\r
150 } else if (!value.equals(other.value)) {
\r
153 if (definingType == null) {
\r
154 if (other.definingType != null) {
\r
157 } else if ((definingType != null) && (other.definingType != null)) {
\r
158 if (!definingType.getPackageName().equals(
\r
159 other.definingType.getPackageName())
\r
160 && !definingType.getName().equals(
\r
161 other.definingType.getName())) {
\r
169 public String toString() {
\r
170 StringBuilder builder = new StringBuilder();
\r
171 builder.append("ConstantImpl [type=");
\r
172 builder.append(type);
\r
173 builder.append(", name=");
\r
174 builder.append(name);
\r
175 builder.append(", value=");
\r
176 builder.append(value);
\r
177 if (definingType != null) {
\r
178 builder.append(", definingType=");
\r
179 builder.append(definingType.getPackageName());
\r
180 builder.append(".");
\r
181 builder.append(definingType.getName());
\r
183 builder.append(", definingType= null");
\r
185 builder.append("]");
\r
186 return builder.toString();
\r