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