ActivitySpec - Correcting logger messages
[sdc.git] / common / openecomp-tosca-datatype / src / main / java / org / openecomp / sdc / tosca / datatypes / model / Constraint.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.tosca.datatypes.model;
22
23 import java.util.ArrayList;
24 import java.util.List;
25
26 public class Constraint {
27   private Object equal;
28   private Object greater_or_equal;
29   private Object greater_than;
30   private Object less_than;
31   private Object less_or_equal;
32   private Object[] in_range;
33   private List<Object> valid_values;
34   private Integer length;
35   private Integer min_length;
36   private Integer max_length;
37   private Object pattern;
38
39   public Constraint() {
40   }
41
42   public Object getGreater_or_equal() {
43     return greater_or_equal;
44   }
45
46   public void setGreater_or_equal(Object greater_or_equal) {
47     this.greater_or_equal = greater_or_equal;
48   }
49
50   public Object getEqual() {
51     return equal;
52   }
53
54   public void setEqual(Object equal) {
55     this.equal = equal;
56   }
57
58   public Object getGreater_than() {
59     return greater_than;
60   }
61
62   public void setGreater_than(Object greater_than) {
63     this.greater_than = greater_than;
64   }
65
66   public Object getLess_than() {
67     return less_than;
68   }
69
70   public void setLess_than(Object less_than) {
71     this.less_than = less_than;
72   }
73
74   public Object getLess_or_equal() {
75     return less_or_equal;
76   }
77
78   public void setLess_or_equal(Object less_or_equal) {
79     this.less_or_equal = less_or_equal;
80   }
81
82   public Object[] getIn_range() {
83     return in_range;
84   }
85
86   /**
87    * Sets in_range attribute.
88    * @param in_range.
89    */
90   public void setIn_range(Object[] in_range) {
91     this.in_range = new Object[2];
92     this.in_range[0] = in_range[0];
93     this.in_range[1] = in_range[1];
94   }
95
96   public List<Object> getValid_values() {
97     return valid_values;
98   }
99
100   public void setValid_values(List<Object> valid_values) {
101     this.valid_values = valid_values;
102   }
103
104   /**
105    * Add Valid value
106    * @param validValue object.
107    */
108   public void addValidValue(Object validValue) {
109     if (this.valid_values == null) {
110       this.valid_values = new ArrayList<>();
111     }
112     valid_values.add(validValue);
113   }
114
115   public Integer getLength() {
116     return length;
117   }
118
119   public void setLength(Integer length) {
120     this.length = length;
121   }
122
123   public Integer getMin_length() {
124     return min_length;
125   }
126
127   public void setMin_length(Integer min_length) {
128     this.min_length = min_length;
129   }
130
131   public Integer getMax_length() {
132     return max_length;
133   }
134
135   public void setMax_length(Integer max_length) {
136     this.max_length = max_length;
137   }
138
139   public Object getPattern() {
140     return pattern;
141   }
142
143   public void setPattern(Object pattern) {
144     this.pattern = pattern;
145   }
146
147   @Override
148   public Constraint clone() {
149     Constraint constraint = new Constraint();
150     constraint.setEqual(this.getEqual());
151     constraint.setGreater_or_equal(this.getGreater_or_equal());
152     constraint.setGreater_than(this.getGreater_than());
153     cloneInRange(constraint);
154     constraint.setLength(this.getLength());
155     constraint.setLess_or_equal(this.getLess_or_equal());
156     constraint.setLess_than(this.getLess_than());
157     constraint.setMax_length(this.getMax_length());
158     constraint.setMin_length(this.getMin_length());
159     constraint.setPattern(this.getPattern());
160     cloneValidValues(constraint);
161
162     return constraint;
163   }
164
165   private void cloneInRange(Constraint constraint) {
166     if (this.getIn_range() != null) {
167       constraint.setIn_range(new Object[]{this.getIn_range()[0], this.getIn_range()[1]});
168     }
169   }
170
171   private void cloneValidValues(Constraint constraint) {
172     if (this.getValid_values() != null) {
173       constraint.setValid_values(new ArrayList<>());
174       for (Object entry : this.getValid_values()) {
175         constraint.getValid_values().add(entry);
176       }
177     }
178   }
179 }