Merge "make vDNS example use modelVersion string"
[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     public DummyReferenceEntity(DummyReferenceEntity source) {
65         this.key = source.key;
66         this.doubleValue = source.doubleValue;
67     }
68
69     /**
70      * Constructor.
71      *
72      * @param key the key
73      * @param doubleValue the double value
74      */
75     public DummyReferenceEntity(final PfReferenceKey key, final double doubleValue) {
76         this.key = key;
77         this.doubleValue = doubleValue;
78     }
79
80     @Override
81     public List<PfKey> getKeys() {
82         final List<PfKey> keyList = new ArrayList<>();
83         keyList.add(getKey());
84         return keyList;
85     }
86
87     @Override
88     public PfValidationResult validate(final PfValidationResult result) {
89         return key.validate(result);
90     }
91
92     @Override
93     public void clean() {
94         key.clean();
95     }
96
97
98     @Override
99     public int compareTo(final PfConcept otherObj) {
100         Assertions.argumentNotNull(otherObj, "comparison object may not be null");
101
102         if (this == otherObj) {
103             return 0;
104         }
105         if (getClass() != otherObj.getClass()) {
106             return this.hashCode() - otherObj.hashCode();
107         }
108
109         final DummyReferenceEntity other = (DummyReferenceEntity) otherObj;
110
111         return Double.compare(doubleValue, other.doubleValue);
112     }
113 }