0dee8b40243523f874a7394caeeb24890522d383
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DummyTimestampEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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 java.util.ArrayList;
24 import java.util.List;
25
26 import javax.persistence.Column;
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30
31 import lombok.Data;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
34
35 import org.onap.policy.models.base.PfConcept;
36 import org.onap.policy.models.base.PfKey;
37 import org.onap.policy.models.base.PfTimestampKey;
38 import org.onap.policy.models.base.PfValidationResult;
39
40 @Entity
41 @Table(name = "DummyTimestampEntity")
42 @Data
43 @EqualsAndHashCode(callSuper = false)
44 public class DummyTimestampEntity extends PfConcept {
45     private static final long serialVersionUID = -2962570563281067895L;
46
47     @EmbeddedId()
48     @NonNull
49     private PfTimestampKey key;
50
51     @Column
52     private double doubleValue;
53
54     /**
55      * Default constructor.
56      */
57     public DummyTimestampEntity() {
58         this.key = new PfTimestampKey();
59         this.doubleValue = 123.45;
60     }
61
62     public DummyTimestampEntity(DummyTimestampEntity source) {
63         this.key = source.key;
64         this.doubleValue = source.doubleValue;
65     }
66
67     /**
68      * Constructor.
69      *
70      * @param key the key
71      * @param doubleValue the double value
72      */
73     public DummyTimestampEntity(final PfTimestampKey key, final double doubleValue) {
74         this.key = key;
75         this.doubleValue = doubleValue;
76     }
77
78     @Override
79     public List<PfKey> getKeys() {
80         final List<PfKey> keyList = new ArrayList<>();
81         keyList.add(getKey());
82         return keyList;
83     }
84
85     @Override
86     public PfValidationResult validate(final PfValidationResult result) {
87         return key.validate(result);
88     }
89
90     @Override
91     public void clean() {
92         key.clean();
93     }
94
95     @Override
96     public int compareTo(@NonNull final PfConcept otherObj) {
97         if (this == otherObj) {
98             return 0;
99         }
100         if (getClass() != otherObj.getClass()) {
101             return this.getClass().getName().compareTo(otherObj.getClass().getName());
102         }
103
104         final DummyTimestampEntity other = (DummyTimestampEntity) otherObj;
105
106         return Double.compare(doubleValue, other.doubleValue);
107     }
108 }