dad167d02e02b0c704a74a8259411395e9ccdf29
[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      * {@inheritDoc}.
81      */
82     @Override
83     public AxArtifactKey getKey() {
84         return key;
85     }
86
87     /**
88      * {@inheritDoc}.
89      */
90     @Override
91     public List<AxKey> getKeys() {
92         return Arrays.asList((AxKey) getKey());
93     }
94
95     /**
96      * Sets the key.
97      *
98      * @param key the new key
99      */
100     public void setKey(final AxArtifactKey key) {
101         this.key = key;
102     }
103
104     /**
105      * Check set key.
106      *
107      * @return true, if successful
108      */
109     public boolean checkSetKey() {
110         return (this.key != null);
111     }
112
113     /**
114      * Gets the double value.
115      *
116      * @return the double value
117      */
118     public double getDoubleValue() {
119         return doubleValue;
120     }
121
122     /**
123      * Sets the double value.
124      *
125      * @param doubleValue the new double value
126      */
127     public void setDoubleValue(final double doubleValue) {
128         this.doubleValue = doubleValue;
129     }
130
131     /**
132      * {@inheritDoc}.
133      */
134     @Override
135     public AxValidationResult validate(final AxValidationResult result) {
136         return key.validate(result);
137     }
138
139     /**
140      * {@inheritDoc}.
141      */
142     @Override
143     public void clean() {
144         key.clean();
145     }
146
147     /**
148      * {@inheritDoc}.
149      */
150     @Override
151     public String toString() {
152         return "ArtifactKeyTestEntity [key=" + key + ", doubleValue=" + doubleValue + "]";
153     }
154
155     /**
156      * {@inheritDoc}.
157      */
158     @Override
159     public AxConcept copyTo(final AxConcept target) {
160         final Object copyObject = ((target == null) ? new ArtifactKeyTestEntity() : target);
161         if (copyObject instanceof ArtifactKeyTestEntity) {
162             final ArtifactKeyTestEntity copy = ((ArtifactKeyTestEntity) copyObject);
163             if (this.checkSetKey()) {
164                 copy.setKey(new AxArtifactKey(key));
165             } else {
166                 copy.key = null;
167             }
168             copy.doubleValue = doubleValue;
169             return copy;
170         } else {
171             return null;
172         }
173     }
174
175     /**
176      * {@inheritDoc}.
177      */
178     @Override
179     public int hashCode() {
180         final int prime = 31;
181         int result = 1;
182         result = prime * result + ((key == null) ? 0 : key.hashCode());
183         return result;
184     }
185
186     /**
187      * {@inheritDoc}.
188      */
189     @Override
190     public boolean equals(final Object obj) {
191         if (obj == null) {
192             return false;
193         }
194         if (this == obj) {
195             return true;
196         }
197         if (getClass() != obj.getClass()) {
198             return false;
199         }
200         final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) obj;
201         if (key == null) {
202             if (other.key != null) {
203                 return false;
204             }
205         } else if (!key.equals(other.key)) {
206             return false;
207         }
208         return (Double.compare(doubleValue, other.doubleValue) == 0);
209     }
210
211     /**
212      * {@inheritDoc}.
213      */
214     @Override
215     public int compareTo(final AxConcept otherObj) {
216         if (otherObj == null) {
217             return -1;
218         }
219         if (this == otherObj) {
220             return 0;
221         }
222         if (getClass() != otherObj.getClass()) {
223             return -1;
224         }
225         final ArtifactKeyTestEntity other = (ArtifactKeyTestEntity) otherObj;
226         if (key == null) {
227             if (other.key != null) {
228                 return 1;
229             }
230         } else if (!key.equals(other.key)) {
231             return key.compareTo(other.key);
232         }
233         return Double.compare(doubleValue, other.doubleValue);
234     }
235 }