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;
86 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
89 public AxReferenceKey getKey() {
96 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
99 public List<AxKey> getKeys() {
100 return Arrays.asList((AxKey) getKey());
106 * @param key the new key
108 public void setKey(final AxReferenceKey key) {
115 * @return true, if successful
117 public boolean checkSetKey() {
118 return (this.key != null);
122 * Gets the double value.
124 * @return the double value
126 public double getDoubleValue() {
131 * Sets the double value.
133 * @param doubleValue the new double value
135 public void setDoubleValue(final double doubleValue) {
136 this.doubleValue = doubleValue;
143 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
144 * AxValidationResult)
147 public AxValidationResult validate(final AxValidationResult result) {
148 return key.validate(result);
154 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
157 public void clean() {
164 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
167 public String toString() {
168 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
175 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
179 public AxConcept copyTo(final AxConcept target) {
180 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
181 if (copyObject instanceof ReferenceKeyTestEntity) {
182 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
183 if (this.checkSetKey()) {
184 copy.setKey(new AxReferenceKey(key));
188 copy.doubleValue = doubleValue;
198 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
201 public int hashCode() {
202 final int prime = 31;
204 result = prime * result + ((key == null) ? 0 : key.hashCode());
211 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
214 public boolean equals(final Object obj) {
221 if (getClass() != obj.getClass()) {
224 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
226 if (other.key != null) {
229 } else if (!key.equals(other.key)) {
232 return (Double.compare(doubleValue, other.doubleValue) == 0);
238 * @see java.lang.Comparable#compareTo(java.lang.Object)
241 public int compareTo(final AxConcept otherObj) {
242 if (otherObj == null) {
245 if (this == otherObj) {
248 if (getClass() != otherObj.getClass()) {
251 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
253 if (other.key != null) {
256 } else if (!key.equals(other.key)) {
257 return key.compareTo(other.key);
259 return Double.compare(doubleValue, other.doubleValue);