2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
4 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.tosca.simple.concepts;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.persistence.ElementCollection;
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 valid_values TOSCA constraint.
37 * @author Chenfei Gao (cgao@research.att.com)
39 @EqualsAndHashCode(callSuper = false)
41 public class JpaToscaConstraintValidValues extends JpaToscaConstraint {
42 private static final long serialVersionUID = -5060193250508635456L;
46 private List<String> validValues;
49 * Constructor to set the valid values.
51 * @param validValues the valid values that are allowed
53 public JpaToscaConstraintValidValues(@NonNull final List<String> validValues) {
54 this.validValues = validValues;
58 * Authorative constructor.
60 * @param authorativeConcept the authorative concept to copy from
62 public JpaToscaConstraintValidValues(final ToscaConstraint authorativeConcept) {
64 * The following will call invoke fromAuthorative() which will populate the class fields.
66 super(authorativeConcept);
70 public ToscaConstraint toAuthorative() {
71 var toscaConstraint = new ToscaConstraint();
73 toscaConstraint.setValidValues(validValues);
75 return toscaConstraint;
79 public void fromAuthorative(final ToscaConstraint toscaConstraint) {
80 validValues = new ArrayList<>();
81 if (toscaConstraint.getValidValues() != null) {
82 validValues.addAll(toscaConstraint.getValidValues());
87 public int compareTo(JpaToscaConstraint otherConstraint) {
88 if (otherConstraint == null) {
91 if (this == otherConstraint) {
94 if (getClass() != otherConstraint.getClass()) {
95 return getClass().getName().compareTo(otherConstraint.getClass().getName());
98 final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConstraint;
100 return PfUtils.compareObjects(validValues, other.validValues);