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