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