Java 17 Upgrade
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyReferenceEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019, 2023 Nordix Foundation.
4  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.dao;
23
24 import jakarta.persistence.Column;
25 import jakarta.persistence.EmbeddedId;
26 import jakarta.persistence.Entity;
27 import jakarta.persistence.Table;
28 import java.io.Serial;
29 import java.util.ArrayList;
30 import java.util.List;
31 import lombok.Data;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
34 import org.onap.policy.common.parameters.BeanValidationResult;
35 import org.onap.policy.common.utils.validation.Assertions;
36 import org.onap.policy.models.base.PfConcept;
37 import org.onap.policy.models.base.PfKey;
38 import org.onap.policy.models.base.PfReferenceKey;
39
40 @Entity
41 @Table(name = "DummyReferenceEntity")
42 @Data
43 @EqualsAndHashCode(callSuper = false)
44 public class DummyReferenceEntity extends PfConcept {
45     @Serial
46     private static final long serialVersionUID = -2962570563281067894L;
47
48     @EmbeddedId()
49     @NonNull
50     private PfReferenceKey key;
51
52     @Column
53     private double doubleValue;
54
55     /**
56      * Default constructor.
57      */
58     public DummyReferenceEntity() {
59         this.key = new PfReferenceKey();
60         this.doubleValue = 123.45;
61     }
62
63     public DummyReferenceEntity(DummyReferenceEntity source) {
64         this.key = source.key;
65         this.doubleValue = source.doubleValue;
66     }
67
68     /**
69      * Constructor.
70      *
71      * @param key the key
72      * @param doubleValue the double value
73      */
74     public DummyReferenceEntity(final PfReferenceKey key, final double doubleValue) {
75         this.key = key;
76         this.doubleValue = doubleValue;
77     }
78
79     @Override
80     public List<PfKey> getKeys() {
81         final List<PfKey> keyList = new ArrayList<>();
82         keyList.add(getKey());
83         return keyList;
84     }
85
86     @Override
87     public BeanValidationResult validate(@NonNull String fieldName) {
88         BeanValidationResult result = new BeanValidationResult(fieldName, this);
89         result.addResult(key.validate("key"));
90         return result;
91     }
92
93     @Override
94     public void clean() {
95         key.clean();
96     }
97
98
99     @Override
100     public int compareTo(final PfConcept otherObj) {
101         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
102
103         if (this == otherObj) {
104             return 0;
105         }
106         if (getClass() != otherObj.getClass()) {
107             return this.hashCode() - otherObj.hashCode();
108         }
109
110         final DummyReferenceEntity other = (DummyReferenceEntity) otherObj;
111
112         return Double.compare(doubleValue, other.doubleValue);
113     }
114 }