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;
25 import javax.persistence.EmbeddedId;
26 import javax.persistence.Entity;
27 import javax.persistence.Table;
28 import javax.xml.bind.annotation.XmlElement;
29 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
34 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
37 * The Class ReferenceKeyTestEntity provides a reference key test concept.
40 @Table(name = "ReferenceKeyTestEntity")
41 public class ReferenceKeyTestEntity extends AxConcept {
42 private static final long serialVersionUID = -2962570563281067895L;
45 @XmlElement(name = "key", required = true)
46 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
47 protected AxReferenceKey key;
49 private double doubleValue;
52 * Instantiates a new reference key test entity.
54 public ReferenceKeyTestEntity() {
55 this.key = new AxReferenceKey();
60 * Instantiates a new reference key test entity.
62 * @param doubleValue the double value
64 public ReferenceKeyTestEntity(final Double doubleValue) {
65 this.key = new AxReferenceKey();
66 this.doubleValue = doubleValue;
70 * Instantiates a new reference key test entity.
73 * @param doubleValue the double value
75 public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
77 this.doubleValue = doubleValue;
84 public AxReferenceKey getKey() {
92 public List<AxKey> getKeys() {
93 return Arrays.asList((AxKey) getKey());
99 * @param key the new key
101 public void setKey(final AxReferenceKey key) {
108 * @return true, if successful
110 public boolean checkSetKey() {
111 return (this.key != null);
115 * Gets the double value.
117 * @return the double value
119 public double getDoubleValue() {
124 * Sets the double value.
126 * @param doubleValue the new double value
128 public void setDoubleValue(final double doubleValue) {
129 this.doubleValue = doubleValue;
136 public AxValidationResult validate(final AxValidationResult result) {
137 return key.validate(result);
144 public void clean() {
152 public String toString() {
153 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
160 public AxConcept copyTo(final AxConcept target) {
161 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
162 if (copyObject instanceof ReferenceKeyTestEntity) {
163 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
164 if (this.checkSetKey()) {
165 copy.setKey(new AxReferenceKey(key));
169 copy.doubleValue = doubleValue;
180 public int hashCode() {
181 final int prime = 31;
183 result = prime * result + ((key == null) ? 0 : key.hashCode());
191 public boolean equals(final Object obj) {
198 if (getClass() != obj.getClass()) {
201 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
203 if (other.key != null) {
206 } else if (!key.equals(other.key)) {
209 return (Double.compare(doubleValue, other.doubleValue) == 0);
216 public int compareTo(final AxConcept otherObj) {
217 if (otherObj == null) {
220 if (this == otherObj) {
223 if (getClass() != otherObj.getClass()) {
226 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
228 if (other.key != null) {
231 } else if (!key.equals(other.key)) {
232 return key.compareTo(other.key);
234 return Double.compare(doubleValue, other.doubleValue);