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.yangtools.binding.generator.util.generated.type.builder;
10 import org.opendaylight.yangtools.sal.binding.model.api.Constant;
11 import org.opendaylight.yangtools.sal.binding.model.api.Type;
13 final class ConstantImpl implements Constant {
15 private final Type definingType;
16 private final Type type;
17 private final String name;
18 private final Object value;
20 public ConstantImpl(final Type definingType, final Type type, final String name, final Object value) {
22 this.definingType = definingType;
29 public Type getDefiningType() {
34 public Type getType() {
39 public String getName() {
44 public Object getValue() {
49 public String toFormattedString() {
50 StringBuilder builder = new StringBuilder();
55 builder.append(value);
56 return builder.toString();
62 * @see java.lang.Object#hashCode()
65 public int hashCode() {
68 result = prime * result + ((name == null) ? 0 : name.hashCode());
69 result = prime * result + ((type == null) ? 0 : type.hashCode());
76 * @see java.lang.Object#equals(java.lang.Object)
79 public boolean equals(Object obj) {
86 if (getClass() != obj.getClass()) {
89 ConstantImpl other = (ConstantImpl) obj;
91 if (other.name != null) {
94 } else if (!name.equals(other.name)) {
98 if (other.type != null) {
101 } else if (!type.equals(other.type)) {
105 if (other.value != null) {
108 } else if (!value.equals(other.value)) {
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());
127 builder.append(definingType.getName());
129 builder.append(", definingType= null");
132 return builder.toString();