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