1e4fc58ffedc649cb4c049954188e12a7779743e
[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     public SchemaDefinition() {
41     }
42
43     public SchemaDefinition(String derivedFrom, List<String> constraints,
44                             Map<String, PropertyDataDefinition> properties) {
45         this.setDerivedFrom(derivedFrom);
46         this.setConstraints(constraints);
47         this.setProperties(properties);
48
49     }
50
51     public String getDerivedFrom() {
52         return derivedFrom;
53     }
54
55     public void setProperty(PropertyDataDefinition property) {
56         this.property = property;
57     }
58
59     public PropertyDataDefinition getProperty() {
60         return this.property;
61     }
62
63     public void setDerivedFrom(String derivedFrom) {
64         this.derivedFrom = derivedFrom;
65     }
66
67     public List<String> getConstraints() {
68         return constraints;
69     }
70
71     public void setConstraints(List<String> constraints) {
72         this.constraints = constraints;
73     }
74
75     public Map<String, PropertyDataDefinition> getProperties() {
76         return properties;
77     }
78
79     public void setProperties(Map<String, PropertyDataDefinition> properties) {
80         this.properties = properties;
81     }
82
83     public void addProperty(String key, PropertyDataDefinition property) {
84
85         properties.put(key, property);
86     }
87
88     @Override
89     public int hashCode() {
90         final int prime = 31;
91         int result = 1;
92         result = prime * result + ((constraints == null) ? 0 : constraints.hashCode());
93         result = prime * result + ((derivedFrom == null) ? 0 : derivedFrom.hashCode());
94         result = prime * result + ((properties == null) ? 0 : properties.hashCode());
95         result = prime * result + ((property == null) ? 0 : property.hashCode());
96         return result;
97     }
98
99     @Override
100     public boolean equals(Object obj) {
101         if (this == obj) {
102             return true;
103         }
104         if (obj == null) {
105             return false;
106         }
107         if (getClass() != obj.getClass()) {
108             return false;
109         }
110         SchemaDefinition other = (SchemaDefinition) obj;
111         if (constraints == null) {
112             if (other.constraints != null) {
113                 return false;
114             }
115         } else if (!constraints.equals(other.constraints)) {
116             return false;
117         }
118         if (derivedFrom == null) {
119             if (other.derivedFrom != null) {
120                 return false;
121             }
122         } else if (!derivedFrom.equals(other.derivedFrom)) {
123             return false;
124         }
125         if (properties == null) {
126             if (other.properties != null) {
127                 return false;
128             }
129         } else if (!properties.equals(other.properties)) {
130             return false;
131         }
132         if (property == null) {
133             return other.property == null;
134         } else {
135             return property.equals(other.property);
136         }
137     }
138
139     @Override
140     public String toString() {
141         return "SchemaDefinition [" + "derivedFrom='" + derivedFrom + ", constraints=" + constraints + ", properties="
142                 + properties + ", property=" + property + ']';
143     }
144 }