Merge "Fix more sonar issues in models: yaml to dao"
[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 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
27 import javax.persistence.Column;
28 import javax.persistence.EmbeddedId;
29 import javax.persistence.Entity;
30 import javax.persistence.Table;
31
32 import lombok.Data;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35
36 import org.onap.policy.common.utils.validation.Assertions;
37 import org.onap.policy.models.base.PfConcept;
38 import org.onap.policy.models.base.PfKey;
39 import org.onap.policy.models.base.PfReferenceKey;
40 import org.onap.policy.models.base.PfValidationResult;
41
42 @Entity
43 @Table(name = "DummyReferenceEntity")
44 @Data
45 @EqualsAndHashCode(callSuper = false)
46 public class DummyReferenceEntity extends PfConcept {
47     private static final long serialVersionUID = -2962570563281067894L;
48
49     @EmbeddedId()
50     @NonNull
51     private PfReferenceKey key;
52
53     @Column
54     private double doubleValue;
55
56     /**
57      * Default constructor.
58      */
59     public DummyReferenceEntity() {
60         this.key = new PfReferenceKey();
61         this.doubleValue = 123.45;
62     }
63
64     /**
65      * Constructor.
66      *
67      * @param key the key
68      * @param doubleValue the double value
69      */
70     public DummyReferenceEntity(final PfReferenceKey key, final double doubleValue) {
71         this.key = key;
72         this.doubleValue = doubleValue;
73     }
74
75     @Override
76     public List<PfKey> getKeys() {
77         final List<PfKey> keyList = new ArrayList<>();
78         keyList.add(getKey());
79         return keyList;
80     }
81
82     @Override
83     public PfValidationResult validate(final PfValidationResult result) {
84         return key.validate(result);
85     }
86
87     @Override
88     public void clean() {
89         key.clean();
90     }
91
92     @Override
93     public PfConcept copyTo(final PfConcept target) {
94         Assertions.argumentNotNull(target, "target may not be null");
95
96         final PfConcept copyObject = target;
97         Assertions.instanceOf(copyObject, DummyReferenceEntity.class);
98
99         final DummyReferenceEntity copy = ((DummyReferenceEntity) copyObject);
100         copy.setKey(key);
101         copy.setDoubleValue(doubleValue);
102
103         return copyObject;
104     }
105
106
107     @Override
108     public int compareTo(final PfConcept otherObj) {
109         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
110
111         if (this == otherObj) {
112             return 0;
113         }
114         if (getClass() != otherObj.getClass()) {
115             return this.hashCode() - otherObj.hashCode();
116         }
117
118         final DummyReferenceEntity other = (DummyReferenceEntity) otherObj;
119
120         return Double.compare(doubleValue, other.doubleValue);
121     }
122 }