Merge changes Ia268965a,Iefa79f99
[controller.git] / opendaylight / config / yang-jmx-generator / src / main / java / org / opendaylight / controller / config / yangjmxgenerator / attribute / DependencyAttribute.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.controller.config.yangjmxgenerator.attribute;
9
10 import org.opendaylight.controller.config.yangjmxgenerator.ServiceInterfaceEntry;
11 import org.opendaylight.yangtools.binding.generator.util.Types;
12 import org.opendaylight.yangtools.sal.binding.model.api.Type;
13 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
14
15 import javax.management.ObjectName;
16 import javax.management.openmbean.SimpleType;
17
18 public class DependencyAttribute extends AbstractAttribute implements
19         TypedAttribute {
20
21     private final Dependency dependency;
22     private final String nullableDescription, nullableDefault;
23
24     public DependencyAttribute(DataSchemaNode attrNode,
25             ServiceInterfaceEntry sie, boolean mandatory,
26             String nullableDescription) {
27         super(attrNode);
28         dependency = new Dependency(sie, mandatory);
29         this.nullableDescription = nullableDescription;
30         nullableDefault = null;
31     }
32
33     @Override
34     public Type getType() {
35         return Types.typeForClass(ObjectName.class);
36     }
37
38     public Dependency getDependency() {
39         return dependency;
40     }
41
42     @Override
43     public String getNullableDescription() {
44         return nullableDescription;
45     }
46
47     @Override
48     public String getNullableDefault() {
49         return nullableDefault;
50     }
51
52     @Override
53     public boolean equals(Object o) {
54         if (this == o)
55             return true;
56         if (o == null || getClass() != o.getClass())
57             return false;
58         if (!super.equals(o))
59             return false;
60
61         DependencyAttribute that = (DependencyAttribute) o;
62
63         if (dependency != null ? !dependency.equals(that.dependency)
64                 : that.dependency != null)
65             return false;
66         if (nullableDefault != null ? !nullableDefault
67                 .equals(that.nullableDefault) : that.nullableDefault != null)
68             return false;
69         if (nullableDescription != null ? !nullableDescription
70                 .equals(that.nullableDescription)
71                 : that.nullableDescription != null)
72             return false;
73
74         return true;
75     }
76
77     @Override
78     public int hashCode() {
79         int result = super.hashCode();
80         result = 31 * result + (dependency != null ? dependency.hashCode() : 0);
81         result = 31
82                 * result
83                 + (nullableDescription != null ? nullableDescription.hashCode()
84                         : 0);
85         result = 31 * result
86                 + (nullableDefault != null ? nullableDefault.hashCode() : 0);
87         return result;
88     }
89
90     @Override
91     public String toString() {
92         return "DependencyAttribute{" + getAttributeYangName() + ","
93                 + "dependency=" + dependency + '}';
94     }
95
96     @Override
97     public SimpleType<?> getOpenType() {
98         return SimpleType.OBJECTNAME;
99     }
100
101     public static class Dependency {
102         private final ServiceInterfaceEntry sie;
103         private final boolean mandatory;
104
105         public Dependency(ServiceInterfaceEntry sie, boolean mandatory) {
106             this.sie = sie;
107             this.mandatory = mandatory;
108         }
109
110         public ServiceInterfaceEntry getSie() {
111             return sie;
112         }
113
114         public boolean isMandatory() {
115             return mandatory;
116         }
117
118         @Override
119         public boolean equals(Object o) {
120             if (this == o)
121                 return true;
122             if (o == null || getClass() != o.getClass())
123                 return false;
124
125             Dependency that = (Dependency) o;
126
127             if (mandatory != that.mandatory)
128                 return false;
129             if (!sie.equals(that.sie))
130                 return false;
131
132             return true;
133         }
134
135         @Override
136         public int hashCode() {
137             int result = sie.hashCode();
138             result = 31 * result + (mandatory ? 1 : 0);
139             return result;
140         }
141     }
142
143 }