Sync Integ to Master
[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 org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
24
25 import java.io.Serializable;
26 import java.util.List;
27 import java.util.Map;
28
29 /**
30  * Schema allows to create new types that can be used along TOSCA definitions.
31  */
32 public class SchemaDefinition extends ToscaDataDefinition implements Serializable {
33
34         /**
35          * 
36          */
37         private static final long serialVersionUID = 7117891081909380577L;
38         
39         private String derivedFrom;
40         private List<String> constraints;
41         private Map<String, PropertyDataDefinition> properties;
42
43         private PropertyDataDefinition property;
44
45         
46
47         public SchemaDefinition() {
48                 super();
49
50         }
51
52         public SchemaDefinition(String derivedFrom, List<String> constraints,
53                         Map<String, PropertyDataDefinition> properties) {
54                 super();
55                 
56                 this.setDerivedFrom(derivedFrom);
57                 this.setConstraints( constraints);
58                 this.setProperties( properties);
59                 
60         }
61
62         public String getDerivedFrom() {
63                 return derivedFrom;
64         }
65
66         public void setProperty(PropertyDataDefinition property) {
67                 this.property = property;
68         }
69
70         public PropertyDataDefinition getProperty() {
71                 return this.property;
72         }
73
74         public void setDerivedFrom(String derivedFrom) {
75                 this.derivedFrom = derivedFrom;
76         }
77
78         public List<String> getConstraints() {
79                 return constraints;
80         }
81
82         public void setConstraints(List<String> constraints) {
83                 this.constraints = constraints;
84         }
85
86         public Map<String, PropertyDataDefinition> getProperties() {
87                 return properties;
88         }
89
90         public void setProperties(Map<String, PropertyDataDefinition> properties) {
91                 this.properties = properties;
92         }
93
94         public void addProperty(String key, PropertyDataDefinition property) {
95
96                 properties.put(key, property);
97         }
98
99         @Override
100         public int hashCode() {
101                 final int prime = 31;
102                 int result = 1;
103                 result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
104                 result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
105                 result = prime * result + ((properties == null) ? 0 : properties.hashCode());
106                 result = prime * result + ((property == null) ? 0 : property.hashCode());
107                 return result;
108         }
109
110         @Override
111         public boolean equals(Object obj) {
112                 if (this == obj)
113                         return true;
114                 if (obj == null)
115                         return false;
116                 if (getClass() != obj.getClass())
117                         return false;
118                 SchemaDefinition other = (SchemaDefinition) obj;
119                 if (constraints == null) {
120                         if (other.constraints != null)
121                                 return false;
122                 } else if (!constraints.equals(other.constraints))
123                         return false;
124                 if (derivedFrom == null) {
125                         if (other.derivedFrom != null)
126                                 return false;
127                 } else if (!derivedFrom.equals(other.derivedFrom))
128                         return false;
129                 if (properties == null) {
130                         if (other.properties != null)
131                                 return false;
132                 } else if (!properties.equals(other.properties))
133                         return false;
134                 if (property == null) {
135                         if (other.property != null)
136                                 return false;
137                 } else if (!property.equals(other.property))
138                         return false;
139                 return true;
140         }
141
142         @Override
143         public String toString() {
144                 return "SchemaDefinition [" + "derivedFrom='" + derivedFrom + ", constraints=" + constraints + ", properties="
145                                 + properties + ", property=" + property + ']';
146         }
147 }