aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-tosca-lib/src/main/java/org/openecomp/sdc/tosca/datatypes/model/Constraint.java
blob: 2c39ce39020cc85bc9e3bd8ae8ba2a9fd694f35e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdc.tosca.datatypes.model;

import java.util.ArrayList;
import java.util.List;

public class Constraint {
  private Object equal;
  private Object greater_or_equal;
  private Object greater_than;
  private Object less_than;
  private Object less_or_equal;
  private Object[] in_range;
  private List<Object> valid_values;
  private Integer length;
  private Integer min_length;
  private Integer max_length;
  private Object pattern;

  public Constraint() {
  }

  public Object getGreater_or_equal() {
    return greater_or_equal;
  }

  public void setGreater_or_equal(Object greaterOrEqual) {
    this.greater_or_equal = greaterOrEqual;
  }

  public Object getEqual() {
    return equal;
  }

  public void setEqual(Object equal) {
    this.equal = equal;
  }

  public Object getGreater_than() {
    return greater_than;
  }

  public void setGreater_than(Object greaterThan) {
    this.greater_than = greaterThan;
  }

  public Object getLess_than() {
    return less_than;
  }

  public void setLess_than(Object lessThan) {
    this.less_than = lessThan;
  }

  public Object getLess_or_equal() {
    return less_or_equal;
  }

  public void setLess_or_equal(Object lessOrEqual) {
    this.less_or_equal = lessOrEqual;
  }

  public Object[] getIn_range() {
    return in_range;
  }

  /**
   * Sets in range.
   *
   * @param inRange the in range
   */
  public void setIn_range(Object[] inRange) {
    this.in_range = new Object[2];
    this.in_range[0] = inRange[0];
    this.in_range[1] = inRange[1];
  }

  public List<Object> getValid_values() {
    return valid_values;
  }

  public void setValid_values(List<Object> validValues) {
    this.valid_values = validValues;
  }

  /**
   * Add valid value.
   *
   * @param validValue the valid value
   */
  public void addValidValue(Object validValue) {
    if (this.valid_values == null) {
      this.valid_values = new ArrayList<>();
    }
    valid_values.add(validValue);
  }

  public Integer getLength() {
    return length;
  }

  public void setLength(Integer length) {
    this.length = length;
  }

  public Integer getMin_length() {
    return min_length;
  }

  public void setMin_length(Integer minLength) {
    this.min_length = minLength;
  }

  public Integer getMax_length() {
    return max_length;
  }

  public void setMax_length(Integer maxLength) {
    this.max_length = maxLength;
  }

  public Object getPattern() {
    return pattern;
  }

  public void setPattern(Object pattern) {
    this.pattern = pattern;
  }

  @Override
  public Constraint clone() {
    Constraint constraint = new Constraint();
    constraint.setEqual(this.getEqual());
    constraint.setGreater_or_equal(this.getGreater_or_equal());
    constraint.setGreater_than(this.getGreater_than());
    cloneInRange(constraint);
    constraint.setLength(this.getLength());
    constraint.setLess_or_equal(this.getLess_or_equal());
    constraint.setLess_than(this.getLess_than());
    constraint.setMax_length(this.getMax_length());
    constraint.setMin_length(this.getMin_length());
    constraint.setPattern(this.getPattern());
    cloneValidValues(constraint);

    return constraint;
  }

  private void cloneInRange(Constraint constraint) {
    if (this.getIn_range() != null) {
      constraint.setIn_range(new Object[]{this.getIn_range()[0], this.getIn_range()[1]});
    }
  }

  private void cloneValidValues(Constraint constraint) {
    if (this.getValid_values() != null) {
      constraint.setValid_values(new ArrayList<>());
      for (Object entry : this.getValid_values()) {
        constraint.getValid_values().add(entry);
      }
    }
  }
}