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