Add DAO module for Models
[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  * ================================================================================
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.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 import org.onap.policy.models.base.PfValidationResult;
40
41 @Entity
42 @Table(name = "DummyReferenceEntity")
43 @Data
44 @EqualsAndHashCode(callSuper = false)
45 public class DummyReferenceEntity extends PfConcept {
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     /**
64      * Constructor.
65      *
66      * @param key the key
67      * @param doubleValue the double value
68      */
69     public DummyReferenceEntity(final PfReferenceKey key, final double doubleValue) {
70         this.key = key;
71         this.doubleValue = doubleValue;
72     }
73
74     @Override
75     public List<PfKey> getKeys() {
76         final List<PfKey> keyList = new ArrayList<>();
77         keyList.add(getKey());
78         return keyList;
79     }
80
81     @Override
82     public PfValidationResult validate(final PfValidationResult result) {
83         return key.validate(result);
84     }
85
86     @Override
87     public void clean() {
88         key.clean();
89     }
90
91     @Override
92     public PfConcept copyTo(final PfConcept target) {
93         Assertions.argumentNotNull(target, "target may not be null");
94
95         final PfConcept copyObject = target;
96         Assertions.instanceOf(copyObject, DummyReferenceEntity.class);
97
98         final DummyReferenceEntity copy = ((DummyReferenceEntity) copyObject);
99         copy.setKey(key);
100         copy.setDoubleValue(doubleValue);
101
102         return copyObject;
103     }
104
105
106     @Override
107     public int compareTo(final PfConcept otherObj) {
108         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
109
110         if (this == otherObj) {
111             return 0;
112         }
113         if (getClass() != otherObj.getClass()) {
114             return this.hashCode() - otherObj.hashCode();
115         }
116
117         final DummyReferenceEntity other = (DummyReferenceEntity) otherObj;
118
119         return  new Double(doubleValue).compareTo(new Double(other.doubleValue));
120     }
121 }