1ca64c477bb0992cddb9b6f08a5d5b13c095719c
[policy/apex-pdp.git] / testsuites / integration / integration-context-test / src / test / java / org / onap / policy / apex / testsuites / integration / context / entities / ReferenceKeyTestEntity.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
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.apex.testsuites.integration.context.entities;
23
24 import java.util.Arrays;
25 import java.util.List;
26
27 import javax.persistence.EmbeddedId;
28 import javax.persistence.Entity;
29 import javax.persistence.Table;
30 import javax.xml.bind.annotation.XmlElement;
31 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
32
33 import org.onap.policy.apex.model.basicmodel.concepts.AxConcept;
34 import org.onap.policy.apex.model.basicmodel.concepts.AxKey;
35 import org.onap.policy.apex.model.basicmodel.concepts.AxReferenceKey;
36 import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
37 import org.onap.policy.apex.model.basicmodel.xml.AxReferenceKeyAdapter;
38
39 /**
40  * The Class ReferenceKeyTestEntity provides a reference key test concept.
41  */
42 @Entity
43 @Table(name = "ReferenceKeyTestEntity")
44 public class ReferenceKeyTestEntity extends AxConcept {
45     private static final long serialVersionUID = -2962570563281067895L;
46
47     @EmbeddedId()
48     @XmlElement(name = "key", required = true)
49     @XmlJavaTypeAdapter(AxReferenceKeyAdapter.class)
50     protected AxReferenceKey key;
51
52     private double doubleValue;
53
54     /**
55      * Instantiates a new reference key test entity.
56      */
57     public ReferenceKeyTestEntity() {
58         this.key = new AxReferenceKey();
59         this.doubleValue = 0;
60     }
61
62     /**
63      * Instantiates a new reference key test entity.
64      *
65      * @param doubleValue the double value
66      */
67     public ReferenceKeyTestEntity(final Double doubleValue) {
68         this.key = new AxReferenceKey();
69         this.doubleValue = doubleValue;
70     }
71
72     /**
73      * Instantiates a new reference key test entity.
74      *
75      * @param key the key
76      * @param doubleValue the double value
77      */
78     public ReferenceKeyTestEntity(final AxReferenceKey key, final Double doubleValue) {
79         this.key = key;
80         this.doubleValue = doubleValue;
81     }
82
83     /**
84      * {@inheritDoc}.
85      */
86     @Override
87     public AxReferenceKey getKey() {
88         return key;
89     }
90
91     /**
92      * {@inheritDoc}.
93      */
94     @Override
95     public List<AxKey> getKeys() {
96         return Arrays.asList((AxKey) getKey());
97     }
98
99     /**
100      * Sets the key.
101      *
102      * @param key the new key
103      */
104     public void setKey(final AxReferenceKey key) {
105         this.key = key;
106     }
107
108     /**
109      * Check set key.
110      *
111      * @return true, if successful
112      */
113     public boolean checkSetKey() {
114         return (this.key != null);
115     }
116
117     /**
118      * Gets the double value.
119      *
120      * @return the double value
121      */
122     public double getDoubleValue() {
123         return doubleValue;
124     }
125
126     /**
127      * Sets the double value.
128      *
129      * @param doubleValue the new double value
130      */
131     public void setDoubleValue(final double doubleValue) {
132         this.doubleValue = doubleValue;
133     }
134
135     /**
136      * {@inheritDoc}.
137      */
138     @Override
139     public AxValidationResult validate(final AxValidationResult result) {
140         return key.validate(result);
141     }
142
143     /**
144      * {@inheritDoc}.
145      */
146     @Override
147     public void clean() {
148         key.clean();
149     }
150
151     /**
152      * {@inheritDoc}.
153      */
154     @Override
155     public String toString() {
156         return "ReferenceKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
157     }
158
159     /**
160      * {@inheritDoc}.
161      */
162     @Override
163     public AxConcept copyTo(final AxConcept target) {
164         final Object copyObject = ((target == null) ? new ReferenceKeyTestEntity() : target);
165         if (copyObject instanceof ReferenceKeyTestEntity) {
166             final ReferenceKeyTestEntity copy = ((ReferenceKeyTestEntity) copyObject);
167             if (this.checkSetKey()) {
168                 copy.setKey(new AxReferenceKey(key));
169             } else {
170                 copy.key = null;
171             }
172             copy.doubleValue = doubleValue;
173             return copy;
174         } else {
175             return null;
176         }
177     }
178
179     /**
180      * {@inheritDoc}.
181      */
182     @Override
183     public int hashCode() {
184         final int prime = 31;
185         int result = 1;
186         result = prime * result + ((key == null) ? 0 : key.hashCode());
187         return result;
188     }
189
190     /**
191      * {@inheritDoc}.
192      */
193     @Override
194     public boolean equals(final Object obj) {
195         if (obj == null) {
196             return false;
197         }
198         if (this == obj) {
199             return true;
200         }
201         if (getClass() != obj.getClass()) {
202             return false;
203         }
204         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) obj;
205         if (key == null) {
206             if (other.key != null) {
207                 return false;
208             }
209         } else if (!key.equals(other.key)) {
210             return false;
211         }
212         return (Double.compare(doubleValue, other.doubleValue) == 0);
213     }
214
215     /**
216      * {@inheritDoc}.
217      */
218     @Override
219     public int compareTo(final AxConcept otherObj) {
220         if (otherObj == null) {
221             return -1;
222         }
223         if (this == otherObj) {
224             return 0;
225         }
226         if (getClass() != otherObj.getClass()) {
227             return -1;
228         }
229         final ReferenceKeyTestEntity other = (ReferenceKeyTestEntity) otherObj;
230         if (key == null) {
231             if (other.key != null) {
232                 return 1;
233             }
234         } else if (!key.equals(other.key)) {
235             return key.compareTo(other.key);
236         }
237         return Double.compare(doubleValue, other.doubleValue);
238     }
239 }