2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
4 * Modifications Copyright (C) 2020 Nordix Foundation.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.basicmodel.concepts;
24 import java.util.Arrays;
25 import java.util.List;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
33 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
36 @Table(name = "TestEntity")
38 public class DummyEntity extends AxConcept {
39 private static final long serialVersionUID = -2962570563281067894L;
42 @XmlElement(name = "key", required = true)
43 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
44 protected AxReferenceKey key;
46 private double doubleValue;
48 public DummyEntity() {
49 this.key = new AxReferenceKey();
53 public DummyEntity(Double doubleValue) {
54 this.key = new AxReferenceKey();
55 this.doubleValue = doubleValue;
58 public DummyEntity(AxReferenceKey key, Double doubleValue) {
60 this.doubleValue = doubleValue;
64 public AxReferenceKey getKey() {
69 public List<AxKey> getKeys() {
70 return Arrays.asList((AxKey) getKey());
73 public void setKey(AxReferenceKey key) {
77 public boolean checkSetKey() {
78 return (this.key != null);
81 public double getDoubleValue() {
85 public void setDoubleValue(double doubleValue) {
86 this.doubleValue = doubleValue;
90 public AxValidationResult validate(AxValidationResult result) {
91 return key.validate(result);
100 public String toString() {
101 final StringBuilder builder = new StringBuilder();
102 builder.append("doubleValue=");
103 builder.append(doubleValue);
104 return builder.toString();
108 public AxConcept copyTo(AxConcept target) {
109 final Object copyObject = ((target == null) ? new DummyEntity() : target);
110 if (copyObject instanceof DummyEntity) {
111 final DummyEntity copy = ((DummyEntity) copyObject);
112 if (this.checkSetKey()) {
113 copy.setKey(new AxReferenceKey(key));
117 copy.doubleValue = doubleValue;
125 public int hashCode() {
126 final int prime = 31;
128 result = prime * result + ((key == null) ? 0 : key.hashCode());
133 public boolean equals(Object obj) {
140 if (getClass() != obj.getClass()) {
143 DummyEntity other = (DummyEntity) obj;
145 if (other.key != null) {
148 } else if (!key.equals(other.key)) {
151 if (doubleValue != other.doubleValue) {
158 public int compareTo(AxConcept otherObj) {
159 if (otherObj == null) {
162 if (this == otherObj) {
165 DummyEntity other = (DummyEntity) otherObj;
167 if (other.key != null) {
170 } else if (!key.equals(other.key)) {
171 return key.compareTo(other.key);
173 if (doubleValue != other.doubleValue) {
174 return Double.valueOf(doubleValue).compareTo(other.doubleValue);