2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.hibernate;
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 @Table(name = "ReferenceKeyTestEntity")
40 public class ReferenceKeyTestEntity extends AxConcept {
41 private static final long serialVersionUID = -2962570563281067894L;
44 @XmlElement(name = "key", required = true)
45 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
46 protected AxReferenceKey key;
48 private double doubleValue;
50 public ReferenceKeyTestEntity() {
51 this.key = new AxReferenceKey();
55 public ReferenceKeyTestEntity(final Double doubleValue) {
56 this.key = new AxReferenceKey();
57 this.doubleValue = doubleValue;
60 public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
62 this.doubleValue = doubleValue;
65 public AxReferenceKey getKey() {
69 public List<AxKey> getKeys() {
70 return Arrays.asList((AxKey) getKey());
73 public void setKey(final AxReferenceKey key) {
77 public boolean checkSetKey() {
78 return (this.key != null);
81 public double getDoubleValue() {
85 public void setDoubleValue(final double doubleValue) {
86 this.doubleValue = doubleValue;
90 public AxValidationResult validate(final AxValidationResult result) {
91 return key.validate(result);
100 public String toString() {
101 return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
105 public AxConcept copyTo(final AxConcept target) {
106 final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
107 if (copyObject instanceof ReferenceKeyTestEntity) {
108 final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
109 if (this.checkSetKey()) {
110 copy.setKey(new AxReferenceKey(key));
114 copy.doubleValue = doubleValue;
122 public int hashCode() {
123 final int prime = 31;
125 result = prime * result + ((key == null) ? 0 : key.hashCode());
130 public boolean equals(final Object obj) {
135 if (getClass() != obj.getClass())
137 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
139 if (other.key != null)
141 } else if (!key.equals(other.key))
143 if (doubleValue != other.doubleValue)
149 public int compareTo(final AxConcept otherObj) {
150 if (otherObj == null)
152 if (this == otherObj)
154 final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
156 if (other.key != null)
158 } else if (!key.equals(other.key))
159 return key.compareTo(other.key);
160 if (doubleValue != other.doubleValue)
161 return new Double(doubleValue).compareTo(other.doubleValue);