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