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