2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021, 2023 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 jakarta.persistence.ElementCollection;
24 import java.io.Serial;
25 import java.util.ArrayList;
26 import java.util.List;
27 import lombok.EqualsAndHashCode;
29 import lombok.NonNull;
30 import lombok.ToString;
31 import org.onap.policy.models.base.PfUtils;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
35 * This class represents in_range TOSCA constraint.
37 @EqualsAndHashCode(callSuper = false)
39 public class JpaToscaConstraintInRange extends JpaToscaConstraint {
41 private static final long serialVersionUID = -5060193250508635456L;
45 private List<String> rangeValues;
48 * Constructor to set the range values.
50 * @param rangeValues the range values that are allowed
52 public JpaToscaConstraintInRange(@NonNull final List<String> rangeValues) {
53 this.rangeValues = rangeValues;
57 * Authorative constructor.
59 * @param authorativeConcept the authorative concept to copy from
61 public JpaToscaConstraintInRange(final ToscaConstraint authorativeConcept) {
63 * The following will call invoke fromAuthorative() which will populate the class fields.
65 super(authorativeConcept);
69 public ToscaConstraint toAuthorative() {
70 var toscaConstraint = new ToscaConstraint();
72 toscaConstraint.setRangeValues(rangeValues);
74 return toscaConstraint;
78 public void fromAuthorative(final ToscaConstraint toscaConstraint) {
79 rangeValues = new ArrayList<>();
80 if (toscaConstraint.getRangeValues() != null) {
81 rangeValues.addAll(toscaConstraint.getRangeValues());
86 public int compareTo(@NonNull JpaToscaConstraint otherConstraint) {
87 if (this == otherConstraint) {
90 if (getClass() != otherConstraint.getClass()) {
91 return getClass().getName().compareTo(otherConstraint.getClass().getName());
94 final JpaToscaConstraintInRange other = (JpaToscaConstraintInRange) otherConstraint;
96 return PfUtils.compareObjects(rangeValues, other.rangeValues);