2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.simple.concepts;
23 import java.util.ArrayList;
24 import java.util.List;
25 import javax.persistence.ElementCollection;
26 import lombok.EqualsAndHashCode;
28 import lombok.NonNull;
29 import lombok.ToString;
30 import org.onap.policy.models.base.PfUtils;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
34 * This class represents in_range TOSCA constraint.
36 @EqualsAndHashCode(callSuper = false)
38 public class JpaToscaConstraintInRange extends JpaToscaConstraint {
39 private static final long serialVersionUID = -5060193250508635456L;
43 private List<String> rangeValues;
46 * Constructor to set the range values.
48 * @param rangeValues the range values that are allowed
50 public JpaToscaConstraintInRange(@NonNull final List<String> rangeValues) {
51 this.rangeValues = rangeValues;
55 * Authorative constructor.
57 * @param authorativeConcept the authorative concept to copy from
59 public JpaToscaConstraintInRange(final ToscaConstraint authorativeConcept) {
61 * The following will call invoke fromAuthorative() which will populate the class fields.
63 super(authorativeConcept);
67 public ToscaConstraint toAuthorative() {
68 var toscaConstraint = new ToscaConstraint();
70 toscaConstraint.setRangeValues(rangeValues);
72 return toscaConstraint;
76 public void fromAuthorative(final ToscaConstraint toscaConstraint) {
77 rangeValues = new ArrayList<>();
78 if (toscaConstraint.getRangeValues() != null) {
79 rangeValues.addAll(toscaConstraint.getRangeValues());
84 public int compareTo(JpaToscaConstraint otherConstraint) {
85 if (otherConstraint == null) {
88 if (this == otherConstraint) {
91 if (getClass() != otherConstraint.getClass()) {
92 return getClass().getName().compareTo(otherConstraint.getClass().getName());
95 final JpaToscaConstraintInRange other = (JpaToscaConstraintInRange) otherConstraint;
97 return PfUtils.compareObjects(rangeValues, other.rangeValues);