Rework tosca converter
[clamp.git] / src / main / java / org / onap / clamp / clds / tosca / update / Field.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;
25
26 public class Field {
27     private String title;
28     private Object value;
29     private Boolean visible;
30     private Boolean staticValue;
31
32     public Field(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 Field(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         Field field = (Field) otherField;
102
103         if (title != null ? !title.equals(field.title) : field.title != null) {
104             return false;
105         }
106         if (value != null ? !value.equals(field.value) : field.value != null) {
107             return false;
108         }
109         if (visible != null ? !visible.equals(field.visible) : field.visible != null) {
110             return false;
111         }
112         return staticValue != null ? staticValue.equals(field.staticValue) : field.staticValue == null;
113     }
114
115     @Override
116     public boolean equals(Object object) {
117         if (this == object) {
118             return true;
119         }
120         if (object == null || getClass() != object.getClass()) {
121             return false;
122         }
123
124         Field field = (Field) object;
125
126         return title != null ? title.equals(field.title) : field.title == null;
127     }
128
129     @Override
130     public int hashCode() {
131         return title != null ? title.hashCode() : 0;
132     }
133
134     /**
135      * This method test the entire equality.
136      *
137      * @param field1 object one
138      * @param field2 object two
139      * @return true if they are totally equals (all attributes, false otherwise
140      */
141     public static boolean fieldsEquals(Field field1, Field field2) {
142         return (field2.getTitle().equals(field1.getTitle()) && field2.getValue().equals(field1.getValue())
143                 && field2.getVisible().equals(field1.getVisible())
144                 && field2.getStaticValue().equals(field1.getStaticValue()));
145     }
146
147 }