2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.binding.generator.util.generated.type.builder;
10 import org.opendaylight.controller.sal.binding.model.api.Constant;
11 import org.opendaylight.controller.sal.binding.model.api.Type;
12 import org.opendaylight.controller.sal.binding.model.api.type.builder.ConstantBuilder;
14 final class ConstantBuilderImpl implements ConstantBuilder {
16 private final Type type;
17 private final String name;
20 public ConstantBuilderImpl(Type type, String name, Object value) {
27 public ConstantBuilderImpl(Type type, String name) {
34 public void assignValue(Object value) {
39 public Constant toInstance(final Type definingType) {
40 return new ConstantImpl(definingType, type, name, value);
43 private static final class ConstantImpl implements Constant {
45 final Type definingType;
46 private final Type type;
47 private final String name;
48 private final Object value;
50 public ConstantImpl(final Type definingType, final Type type,
51 final String name, final Object value) {
53 this.definingType = definingType;
60 public Type getDefiningType() {
65 public Type getType() {
70 public String getName() {
75 public Object getValue() {
80 public String toFormattedString() {
81 StringBuilder builder = new StringBuilder();
86 builder.append(value);
87 return builder.toString();
93 * @see java.lang.Object#hashCode()
96 public int hashCode() {
99 result = prime * result + ((name == null) ? 0 : name.hashCode());
100 result = prime * result + ((type == null) ? 0 : type.hashCode());
107 * @see java.lang.Object#equals(java.lang.Object)
110 public boolean equals(Object obj) {
117 if (getClass() != obj.getClass()) {
120 ConstantImpl other = (ConstantImpl) obj;
122 if (other.name != null) {
125 } else if (!name.equals(other.name)) {
129 if (other.type != null) {
132 } else if (!type.equals(other.type)) {
136 if (other.value != null) {
139 } else if (!value.equals(other.value)) {
146 public String toString() {
147 StringBuilder builder = new StringBuilder();
148 builder.append("Constant [type=");
149 builder.append(type);
150 builder.append(", name=");
151 builder.append(name);
152 builder.append(", value=");
153 builder.append(value);
154 if (definingType != null) {
155 builder.append(", definingType=");
156 builder.append(definingType.getPackageName());
158 builder.append(definingType.getName());
160 builder.append(", definingType= null");
163 return builder.toString();