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;
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;
31 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
34 @Table(name = "TestEntity")
36 public class DummyEntity extends AxConcept {
37 private static final long serialVersionUID = -2962570563281067894L;
40 @XmlElement(name = "key", required = true)
41 @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
42 protected AxReferenceKey key;
44 private double doubleValue;
46 public DummyEntity() {
47 this.key = new AxReferenceKey();
51 public DummyEntity(Double doubleValue) {
52 this.key = new AxReferenceKey();
53 this.doubleValue = doubleValue;
56 public DummyEntity(AxReferenceKey key, Double doubleValue) {
58 this.doubleValue = doubleValue;
62 public AxReferenceKey getKey() {
67 public List<AxKey> getKeys() {
68 return Arrays.asList((AxKey) getKey());
71 public void setKey(AxReferenceKey key) {
75 public boolean checkSetKey() {
76 return (this.key != null);
79 public double getDoubleValue() {
83 public void setDoubleValue(double doubleValue) {
84 this.doubleValue = doubleValue;
88 public AxValidationResult validate(AxValidationResult result) {
89 return key.validate(result);
98 public String toString() {
99 final StringBuilder builder = new StringBuilder();
100 builder.append("doubleValue=");
101 builder.append(doubleValue);
102 return builder.toString();
106 public AxConcept copyTo(AxConcept target) {
107 final Object copyObject = ((target == null) ? new DummyEntity() : target);
108 if (copyObject instanceof DummyEntity) {
109 final DummyEntity copy = ((DummyEntity) copyObject);
110 if (this.checkSetKey()) {
111 copy.setKey(new AxReferenceKey(key));
115 copy.doubleValue = doubleValue;
123 public int hashCode() {
124 final int prime = 31;
126 result = prime * result + ((key == null) ? 0 : key.hashCode());
131 public boolean equals(Object obj) {
138 if (getClass() != obj.getClass()) {
141 DummyEntity other = (DummyEntity) obj;
143 if (other.key != null) {
146 } else if (!key.equals(other.key)) {
149 if (doubleValue != other.doubleValue) {
156 public int compareTo(AxConcept otherObj) {
157 if (otherObj == null) {
160 if (this == otherObj) {
163 DummyEntity other = (DummyEntity) otherObj;
165 if (other.key != null) {
168 } else if (!key.equals(other.key)) {
169 return key.compareTo(other.key);
171 if (doubleValue != other.doubleValue) {
172 return Double.valueOf(doubleValue).compareTo(other.doubleValue);