2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2019 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.apex.testsuites.integration.context.entities;
24 import java.util.Arrays;
25 import java.util.List;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
37 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
40 * The Class ReferenceKeyTestEntity provides a reference key test concept.
43 @Table(name = "ReferenceKeyTestEntity")
44 public class ReferenceKeyTestEntity extends AxConcept {
45 private static final long serialVersionUID = -2962570563281067895L;
48 @XmlElement(name = "key", required = true)
49 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
50 protected AxReferenceKey key;
52 private double doubleValue;
55 * Instantiates a new reference key test entity.
57 public ReferenceKeyTestEntity() {
58 this.key = new AxReferenceKey();
63 * Instantiates a new reference key test entity.
65 * @param doubleValue the double value
67 public ReferenceKeyTestEntity(final Double doubleValue) {
68 this.key = new AxReferenceKey();
69 this.doubleValue = doubleValue;
73 * Instantiates a new reference key test entity.
76 * @param doubleValue the double value
78 public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
80 this.doubleValue = doubleValue;
87 public AxReferenceKey getKey() {
95 public List<AxKey> getKeys() {
96 return Arrays.asList((AxKey) getKey());
102 * @param key the new key
104 public void setKey(final AxReferenceKey key) {
111 * @return true, if successful
113 public boolean checkSetKey() {
114 return (this.key != null);
118 * Gets the double value.
120 * @return the double value
122 public double getDoubleValue() {
127 * Sets the double value.
129 * @param doubleValue the new double value
131 public void setDoubleValue(final double doubleValue) {
132 this.doubleValue = doubleValue;
139 public AxValidationResult validate(final AxValidationResult result) {
140 return key.validate(result);
147 public void clean() {
155 public String toString() {
156 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
163 public AxConcept copyTo(final AxConcept target) {
164 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
165 if (copyObject instanceof ReferenceKeyTestEntity) {
166 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
167 if (this.checkSetKey()) {
168 copy.setKey(new AxReferenceKey(key));
172 copy.doubleValue = doubleValue;
183 public int hashCode() {
184 final int prime = 31;
186 result = prime * result + ((key == null) ? 0 : key.hashCode());
194 public boolean equals(final Object obj) {
201 if (getClass() != obj.getClass()) {
204 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
206 if (other.key != null) {
209 } else if (!key.equals(other.key)) {
212 return (Double.compare(doubleValue, other.doubleValue) == 0);
219 public int compareTo(final AxConcept otherObj) {
220 if (otherObj == null) {
223 if (this == otherObj) {
226 if (getClass() != otherObj.getClass()) {
229 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
231 if (other.key != null) {
234 } else if (!key.equals(other.key)) {
235 return key.compareTo(other.key);
237 return Double.compare(doubleValue, other.doubleValue);