Merge "Fix the tosca converter"
[clamp.git] / src / main / java / org / onap / clamp / clds / tosca / update / templates / JsonTemplateField.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2020 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.tosca.update.templates;
25
26 public class JsonTemplateField {
27     private String title;
28     private Object value;
29     private Boolean visible;
30     private Boolean staticValue;
31
32     public JsonTemplateField(String title) {
33         this.title = title;
34     }
35
36     /**
37      * Constructor.
38      *
39      * @param title       The title
40      * @param value       The value
41      * @param visible     visible or not
42      * @param staticValue The static value
43      */
44     public JsonTemplateField(String title, Object value, Boolean visible, Boolean staticValue) {
45         this.title = title;
46         this.value = value;
47         this.visible = visible;
48         this.staticValue = staticValue;
49     }
50
51     public String getTitle() {
52         return title;
53     }
54
55     public void setTitle(String title) {
56         this.title = title;
57     }
58
59     public Object getValue() {
60         return value;
61     }
62
63     public void setValue(Object value) {
64         this.value = value;
65     }
66
67     public Boolean getVisible() {
68         return visible;
69     }
70
71     public void setVisible(Boolean visible) {
72         this.visible = visible;
73     }
74
75     public Boolean getStaticValue() {
76         return staticValue;
77     }
78
79     public void setStaticValue(Boolean staticValue) {
80         this.staticValue = staticValue;
81     }
82
83     public String toString() {
84         return title + " " + value + " " + visible + " " + staticValue;
85     }
86
87     /**
88      * This method compares two fields.
89      *
90      * @param otherField Compare the current object with the one specified
91      * @return true if they are totally equals, false otherwise
92      */
93     public boolean compareWithField(Object otherField) {
94         if (this == otherField) {
95             return true;
96         }
97         if (otherField == null || getClass() != otherField.getClass()) {
98             return false;
99         }
100
101         JsonTemplateField jsonTemplateField = (JsonTemplateField) otherField;
102
103         if (title != null ? !title.equals(jsonTemplateField.title) : jsonTemplateField.title != null) {
104             return false;
105         }
106         if (value != null ? !value.equals(jsonTemplateField.value) : jsonTemplateField.value != null) {
107             return false;
108         }
109         if (visible != null ? !visible.equals(jsonTemplateField.visible) : jsonTemplateField.visible != null) {
110             return false;
111         }
112         return staticValue != null ? staticValue.equals(jsonTemplateField.staticValue) :
113                 jsonTemplateField.staticValue == null;
114     }
115
116     @Override
117     public boolean equals(Object object) {
118         if (this == object) {
119             return true;
120         }
121         if (object == null || getClass() != object.getClass()) {
122             return false;
123         }
124
125         JsonTemplateField jsonTemplateField = (JsonTemplateField) object;
126
127         return title != null ? title.equals(jsonTemplateField.title) : jsonTemplateField.title == null;
128     }
129
130     @Override
131     public int hashCode() {
132         return title != null ? title.hashCode() : 0;
133     }
134
135     /**
136      * This method test the entire equality.
137      *
138      * @param jsonTemplateField1 object one
139      * @param jsonTemplateField2 object two
140      * @return true if they are totally equals (all attributes, false otherwise
141      */
142     public static boolean fieldsEquals(JsonTemplateField jsonTemplateField1, JsonTemplateField jsonTemplateField2) {
143         return (jsonTemplateField2.getTitle().equals(jsonTemplateField1.getTitle())
144                 && jsonTemplateField2.getValue().equals(jsonTemplateField1.getValue())
145                 && jsonTemplateField2.getVisible().equals(jsonTemplateField1.getVisible())
146                 && jsonTemplateField2.getStaticValue().equals(jsonTemplateField1.getStaticValue()));
147     }
148
149 }