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