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