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