Merge "[1707-OS] Updated license text according to the"
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / SchemaDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.datatypes.elements;
22
23 import java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.List;
26 import java.util.Map;
27
28 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
29 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
30
31 /**
32  * Schema allows to create new types that can be used along TOSCA definitions.
33  */
34 public class SchemaDefinition extends ToscaDataDefinition implements Serializable {
35
36         /**
37          * 
38          */
39         private static final long serialVersionUID = 7117891081909380577L;
40         
41         private String derivedFrom;
42         private List<String> constraints;
43         private Map<String, PropertyDataDefinition> properties;
44
45         private PropertyDataDefinition property;
46
47         
48
49         public SchemaDefinition() {
50                 super();
51
52         }
53
54         public SchemaDefinition(String derivedFrom, List<String> constraints,
55                         Map<String, PropertyDataDefinition> properties) {
56                 super();
57                 
58                 this.setDerivedFrom(derivedFrom);
59                 this.setConstraints( constraints);
60                 this.setProperties( properties);
61                 
62         }
63
64         public String getDerivedFrom() {
65                 return derivedFrom;
66         }
67
68         public void setProperty(PropertyDataDefinition property) {
69                 this.property = property;
70         }
71
72         public PropertyDataDefinition getProperty() {
73                 return this.property;
74         }
75
76         public void setDerivedFrom(String derivedFrom) {
77                 this.derivedFrom = derivedFrom;
78         }
79
80         public List<String> getConstraints() {
81                 return constraints;
82         }
83
84         public void setConstraints(List<String> constraints) {
85                 this.constraints = constraints;
86         }
87
88         public Map<String, PropertyDataDefinition> getProperties() {
89                 return properties;
90         }
91
92         public void setProperties(Map<String, PropertyDataDefinition> properties) {
93                 this.properties = properties;
94         }
95
96         public void addProperty(String key, PropertyDataDefinition property) {
97
98                 properties.put(key, property);
99         }
100
101         @Override
102         public int hashCode() {
103                 final int prime = 31;
104                 int result = 1;
105                 result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
106                 result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
107                 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
108                 result = prime * result + ((property == null) ? 0 : property.hashCode());
109                 return result;
110         }
111
112         @Override
113         public boolean equals(Object obj) {
114                 if (this == obj)
115                         return true;
116                 if (obj == null)
117                         return false;
118                 if (getClass() != obj.getClass())
119                         return false;
120                 SchemaDefinition other = (SchemaDefinition) obj;
121                 if (constraints == null) {
122                         if (other.constraints != null)
123                                 return false;
124                 } else if (!constraints.equals(other.constraints))
125                         return false;
126                 if (derivedFrom == null) {
127                         if (other.derivedFrom != null)
128                                 return false;
129                 } else if (!derivedFrom.equals(other.derivedFrom))
130                         return false;
131                 if (properties == null) {
132                         if (other.properties != null)
133                                 return false;
134                 } else if (!properties.equals(other.properties))
135                         return false;
136                 if (property == null) {
137                         if (other.property != null)
138                                 return false;
139                 } else if (!property.equals(other.property))
140                         return false;
141                 return true;
142         }
143
144         @Override
145         public String toString() {
146                 return "SchemaDefinition [" + "derivedFrom='" + derivedFrom + ", constraints=" + constraints + ", properties="
147                                 + properties + ", property=" + property + ']';
148         }
149 }