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;
26 import javax.persistence.EmbeddedId;
27 import javax.persistence.Entity;
28 import javax.persistence.Table;
29 import javax.xml.bind.annotation.XmlElement;
30 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
35 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
38 * The Class ReferenceKeyTestEntity provides a reference key test concept.
41 @Table(name = "ReferenceKeyTestEntity")
42 public class ReferenceKeyTestEntity extends AxConcept {
43 private static final long serialVersionUID = -2962570563281067895L;
46 @XmlElement(name = "key", required = true)
47 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
48 protected AxReferenceKey key;
50 private double doubleValue;
53 * Instantiates a new reference key test entity.
55 public ReferenceKeyTestEntity() {
56 this.key = new AxReferenceKey();
61 * Instantiates a new reference key test entity.
63 * @param doubleValue the double value
65 public ReferenceKeyTestEntity(final Double doubleValue) {
66 this.key = new AxReferenceKey();
67 this.doubleValue = doubleValue;
71 * Instantiates a new reference key test entity.
74 * @param doubleValue the double value
76 public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
78 this.doubleValue = doubleValue;
85 public AxReferenceKey getKey() {
93 public List<AxKey> getKeys() {
94 return Arrays.asList((AxKey) getKey());
100 * @param key the new key
102 public void setKey(final AxReferenceKey key) {
109 * @return true, if successful
111 public boolean checkSetKey() {
112 return (this.key != null);
116 * Gets the double value.
118 * @return the double value
120 public double getDoubleValue() {
125 * Sets the double value.
127 * @param doubleValue the new double value
129 public void setDoubleValue(final double doubleValue) {
130 this.doubleValue = doubleValue;
137 public AxValidationResult validate(final AxValidationResult result) {
138 return key.validate(result);
145 public void clean() {
153 public String toString() {
154 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
161 public AxConcept copyTo(final AxConcept target) {
162 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
163 if (copyObject instanceof ReferenceKeyTestEntity) {
164 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
165 if (this.checkSetKey()) {
166 copy.setKey(new AxReferenceKey(key));
170 copy.doubleValue = doubleValue;
181 public int hashCode() {
182 final int prime = 31;
184 result = prime * result + ((key == null) ? 0 : key.hashCode());
192 public boolean equals(final Object obj) {
199 if (getClass() != obj.getClass()) {
202 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
204 if (other.key != null) {
207 } else if (!key.equals(other.key)) {
210 return (Double.compare(doubleValue, other.doubleValue) == 0);
217 public int compareTo(final AxConcept otherObj) {
218 if (otherObj == null) {
221 if (this == otherObj) {
224 if (getClass() != otherObj.getClass()) {
227 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
229 if (other.key != null) {
232 } else if (!key.equals(other.key)) {
233 return key.compareTo(other.key);
235 return Double.compare(doubleValue, other.doubleValue);