2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.apex.plugins.persistence.jpa.eclipselink.entities;
23 import java.util.Arrays;
24 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;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
36 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
39 * The Class ReferenceKeyTestEntity provides a reference key test concept.
42 @Table(name = "ReferenceKeyTestEntity")
43 public class ReferenceKeyTestEntity extends AxConcept {
44 private static final long serialVersionUID = -2962570563281067895L;
47 @XmlElement(name = "key", required = true)
48 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
49 protected AxReferenceKey key;
51 private double doubleValue;
54 * Instantiates a new reference key test entity.
56 public ReferenceKeyTestEntity() {
57 this.key = new AxReferenceKey();
62 * Instantiates a new reference key test entity.
64 * @param doubleValue the double value
66 public ReferenceKeyTestEntity(final Double doubleValue) {
67 this.key = new AxReferenceKey();
68 this.doubleValue = doubleValue;
72 * Instantiates a new reference key test entity.
75 * @param doubleValue the double value
77 public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
79 this.doubleValue = doubleValue;
85 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKey()
88 public AxReferenceKey getKey() {
95 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#getKeys()
98 public List<AxKey> getKeys() {
99 return Arrays.asList((AxKey) getKey());
105 * @param key the new key
107 public void setKey(final AxReferenceKey key) {
114 * @return true, if successful
116 public boolean checkSetKey() {
117 return (this.key != null);
121 * Gets the double value.
123 * @return the double value
125 public double getDoubleValue() {
130 * Sets the double value.
132 * @param doubleValue the new double value
134 public void setDoubleValue(final double doubleValue) {
135 this.doubleValue = doubleValue;
142 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#validate(org.onap.policy.apex.model.basicmodel.concepts.
143 * AxValidationResult)
146 public AxValidationResult validate(final AxValidationResult result) {
147 return key.validate(result);
153 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#clean()
156 public void clean() {
163 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#toString()
166 public String toString() {
167 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
174 * org.onap.policy.apex.model.basicmodel.concepts.AxConcept#copyTo(org.onap.policy.apex.model.basicmodel.concepts.
178 public AxConcept copyTo(final AxConcept target) {
179 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
180 if (copyObject instanceof ReferenceKeyTestEntity) {
181 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
182 if (this.checkSetKey()) {
183 copy.setKey(new AxReferenceKey(key));
187 copy.doubleValue = doubleValue;
197 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#hashCode()
200 public int hashCode() {
201 final int prime = 31;
203 result = prime * result + ((key == null) ? 0 : key.hashCode());
210 * @see org.onap.policy.apex.model.basicmodel.concepts.AxConcept#equals(java.lang.Object)
213 public boolean equals(final Object obj) {
220 if (getClass() != obj.getClass()) {
223 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
225 if (other.key != null) {
228 } else if (!key.equals(other.key)) {
231 return (Double.compare(doubleValue, other.doubleValue) == 0);
237 * @see java.lang.Comparable#compareTo(java.lang.Object)
240 public int compareTo(final AxConcept otherObj) {
241 if (otherObj == null) {
244 if (this == otherObj) {
247 if (getClass() != otherObj.getClass()) {
250 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
252 if (other.key != null) {
255 } else if (!key.equals(other.key)) {
256 return key.compareTo(other.key);
258 return Double.compare(doubleValue, other.doubleValue);