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