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;
86 public AxReferenceKey getKey() {
94 public List<AxKey> getKeys() {
95 return Arrays.asList((AxKey) getKey());
101 * @param key the new key
103 public void setKey(final AxReferenceKey key) {
110 * @return true, if successful
112 public boolean checkSetKey() {
113 return (this.key != null);
117 * Gets the double value.
119 * @return the double value
121 public double getDoubleValue() {
126 * Sets the double value.
128 * @param doubleValue the new double value
130 public void setDoubleValue(final double doubleValue) {
131 this.doubleValue = doubleValue;
138 public AxValidationResult validate(final AxValidationResult result) {
139 return key.validate(result);
146 public void clean() {
154 public String toString() {
155 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
162 public AxConcept copyTo(final AxConcept target) {
163 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
164 if (copyObject instanceof ReferenceKeyTestEntity) {
165 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
166 if (this.checkSetKey()) {
167 copy.setKey(new AxReferenceKey(key));
171 copy.doubleValue = doubleValue;
182 public int hashCode() {
183 final int prime = 31;
185 result = prime * result + ((key == null) ? 0 : key.hashCode());
193 public boolean equals(final Object obj) {
200 if (getClass() != obj.getClass()) {
203 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
205 if (other.key != null) {
208 } else if (!key.equals(other.key)) {
211 return (Double.compare(doubleValue, other.doubleValue) == 0);
218 public int compareTo(final AxConcept otherObj) {
219 if (otherObj == null) {
222 if (this == otherObj) {
225 if (getClass() != otherObj.getClass()) {
228 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
230 if (other.key != null) {
233 } else if (!key.equals(other.key)) {
234 return key.compareTo(other.key);
236 return Double.compare(doubleValue, other.doubleValue);