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 org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
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.AxValidationResult;
35 * The Class ArtifactKeyTestEntity is an entity for testing artifact keys.
38 @Table(name = "ArtifactKeyTestEntity")
39 public class ArtifactKeyTestEntity extends AxConcept {
40 private static final long serialVersionUID = -2962570563281067896L;
43 @XmlElement(name = "key", required = true)
44 protected AxArtifactKey key;
46 private double doubleValue;
49 * Instantiates a new artifact key test entity.
51 public ArtifactKeyTestEntity() {
52 this.key = new AxArtifactKey();
57 * Instantiates a new artifact key test entity.
59 * @param doubleValue the double value
61 public ArtifactKeyTestEntity(final Double doubleValue) {
62 this.key = new AxArtifactKey();
63 this.doubleValue = doubleValue;
67 * Instantiates a new artifact key test entity.
70 * @param doubleValue the double value
72 public ArtifactKeyTestEntity(final AxArtifactKey key, final Double doubleValue) {
74 this.doubleValue = doubleValue;
81 public AxArtifactKey getKey() {
89 public List<AxKey> getKeys() {
90 return Arrays.asList((AxKey) getKey());
96 * @param key the new key
98 public void setKey(final AxArtifactKey key) {
105 * @return true, if successful
107 public boolean checkSetKey() {
108 return (this.key != null);
112 * Gets the double value.
114 * @return the double value
116 public double getDoubleValue() {
121 * Sets the double value.
123 * @param doubleValue the new double value
125 public void setDoubleValue(final double doubleValue) {
126 this.doubleValue = doubleValue;
133 public AxValidationResult validate(final AxValidationResult result) {
134 return key.validate(result);
141 public void clean() {
149 public String toString() {
150 return "ArtifactKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
157 public AxConcept copyTo(final AxConcept target) {
158 final Object copyObject = ((target == null) ? new ArtifactKeyTestEntity() : target);
159 if (copyObject instanceof ArtifactKeyTestEntity) {
160 final ArtifactKeyTestEntity copy = ((ArtifactKeyTestEntity) copyObject);
161 if (this.checkSetKey()) {
162 copy.setKey(new AxArtifactKey(key));
166 copy.doubleValue = doubleValue;
177 public int hashCode() {
178 final int prime = 31;
180 result = prime * result + ((key == null) ? 0 : key.hashCode());
188 public boolean equals(final Object obj) {
195 if (getClass() != obj.getClass()) {
198 final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) obj;
200 if (other.key != null) {
203 } else if (!key.equals(other.key)) {
206 return (Double.compare(doubleValue, other.doubleValue) == 0);
213 public int compareTo(final AxConcept otherObj) {
214 if (otherObj == null) {
217 if (this == otherObj) {
220 if (getClass() != otherObj.getClass()) {
223 final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) otherObj;
225 if (other.key != null) {
228 } else if (!key.equals(other.key)) {
229 return key.compareTo(other.key);
231 return Double.compare(doubleValue, other.doubleValue);