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