2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
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 com.google.gson.annotations.SerializedName;
25 import java.util.LinkedList;
26 import java.util.List;
27 import javax.persistence.ElementCollection;
28 import javax.ws.rs.core.Response;
31 import lombok.EqualsAndHashCode;
32 import lombok.NonNull;
34 import org.onap.policy.models.base.PfConcept;
35 import org.onap.policy.models.base.PfModelRuntimeException;
36 import org.onap.policy.models.base.PfReferenceKey;
39 * This class represents valid_values TOSCA constraint.
41 * @author Chenfei Gao (cgao@research.att.com)
43 @EqualsAndHashCode(callSuper = false)
45 public class JpaToscaConstraintValidValues extends JpaToscaConstraint {
46 private static final long serialVersionUID = 3152323457560746844L;
48 @SerializedName("valid_values")
51 private final List<String> validValues;
54 * The Default Constructor creates a {@link JpaToscaConstraintValidValues} object with a null key.
56 public JpaToscaConstraintValidValues() {
57 this(new PfReferenceKey());
61 * The Key Constructor creates a {@link JpaToscaConstraintValidValues} object with the given concept key.
63 * @param key the key of the constraint
65 public JpaToscaConstraintValidValues(final PfReferenceKey key) {
67 validValues = new LinkedList<>();
71 * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key
72 * and valid values list.
74 * @param key the key of the constraint
75 * @param validValues the valid values list of the constraint
78 public JpaToscaConstraintValidValues(final PfReferenceKey key, @NonNull final List<String> validValues) {
80 this.validValues = validValues;
86 * @param copyConcept the concept to copy from
88 public JpaToscaConstraintValidValues(@NonNull final JpaToscaConstraintValidValues copyConcept) {
89 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
93 public int compareTo(final PfConcept otherConcept) {
94 if (otherConcept == null) {
97 if (this == otherConcept) {
100 if (getClass() != otherConcept.getClass()) {
101 return this.hashCode() - otherConcept.hashCode();
104 final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConcept;
106 int result = super.compareTo(other);
111 if (validValues.equals(other.validValues)) {
118 public PfConcept copyTo(@NonNull final PfConcept target) {
119 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");